correct way to encode the (forward slash /) in Dynamics BC AL - dynamics-365

I am calling external API from HTTP client
Source Code:
usercontrol(html; HTML)
{
ApplicationArea = all;
trigger ControlReady()
Var
JSONManagement: Codeunit "JSON Management";
"HttpClient": HttpClient;
HttpContent: HttpContent;
HttpMessage: HttpRequestMessage;
HttpRespnse: HttpResponseMessage;
JsonText: Text;
ResponseMessage: Text;
cnew: text;
TypeHelper: Codeunit "Type Helper";
begin
NR := 'SEDC470R/3841D';
IF NR = '' THEN begin
end
ELSE begin
HttpMessage.SetRequestUri('https://.........r.avd.dk/api/97d267826-2dc0/items/' + TypeHelper.UrlEncode(NR) + '/listDummyall?pc=Ja');
HttpClient.Send(HttpMessage, HttpRespnse);
HttpContent := HttpRespnse.Content();
HttpContent.ReadAs(ResponseMessage);
CurrPage.html.Render(ResponseMessage);
end;
end;
}
but it returns a 404 Not Found HTML page. It looks like it's not encoding the forward slash. Is there some other step that I am missing?

I am not exactly sure what you are trying to accomplish.
But the TypeHelper.Encode works for me, so I guess that part is not your problem.
If you just want to display a webpage in BC, did you try the WebPageViewer addin?
pageextension 50100 CustomerListExt extends "Customer Card"
{
layout
{
addlast(content)
{
group(webpage)
{
usercontrol(webViewer; "Microsoft.Dynamics.Nav.Client.WebPageViewer")
{
ApplicationArea = all;
trigger ControlAddInReady(callbackUrl: Text)
begin
CurrPage.webViewer.Navigate('https://stefanmaron.com/');
end;
}
}
}
}
}

Related

How to solve apex.ajax.clob error in Oracle 18c APEX?

I am trying to show pins in my map control and I was using the following code in old theme 4.2 and it was working fine. But with new APEX theme, I am getting apex.ajax.clob is not a constructor error
function refreshMap()
{
var gData;
var clob_ob = new apex.ajax.clob
(
function()
{
var rs = p.readyState
if(rs == 4)
{
gData = p.responseText;
if(gData.length == 0)
{
alert("No task found.");
return;
}
if(gData=='-1')
{
alert("Data too large to be displayed. Filter task by type or select smaller date range.");
return;
}
}
if(gData)
{
var actArray = gData.split("~#~");
var bounds = new google.maps.LatLngBounds();
for(var i=0; i < actArray.length; i++)
{
acct = ""+actArray[i];
var colArray = acct.split("~#~");
var repStatus = colArray[5];
var link = '<b><u>'+colArray[2]+'</u></b>';
var html = '<table><tr><td style="font-weight: bold; font-size: 175%;">'+colArray[3]+'</td></tr></table><table><tr><td> </td></tr><tr><td><b>Task # : </b> </td><td>'+link+'</td></tr><tr><td align="left"><b>Subject : </b> </td><td>'+colArray[4]+'</td></tr><tr><td align="left"><b>Status : </b> </td><td>'+repStatus+'</td></tr></table>';
var newmarker = new google.maps.Marker({
position: new google.maps.LatLng(colArray[0], colArray[1]),
map: map,
//title: html,
icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2|'+colArray[8]
});
newmarker['infowindow'] = new google.maps.InfoWindow({
content: html
});
google.maps.event.addListener(newmarker, 'click', function() {
this['infowindow'].open(map, this);
});
marker.push(newmarker);
bounds.extend(new google.maps.LatLng(colArray[0], colArray[1]));
}
map.fitBounds(bounds);
}
});
clob_ob._get();
}
apex.ajax.clob was deprecated and moved to legacy_18.js (at least in 18.2). To follow the example you have to include /i/libraries/apex/legacy_18.js. This can be done on a page-by-page basis in the Javascript -> File URLs box.
I know this is quite old post, but I found it while experience the same issue and looking for solution. As this was one of the first links to appear for me on Google, after finding the solution, I decided to share a code here for future references.
You'll need to adjust this code to your situation, so please take it as example, how to approach this issue without relying on the legacy javascript.
In this example I've a CLOB which contains HTML source (accepting few parameters) and I need to display it in region on page load.
First you create a AJAX Callback process (let's call this process HTML)
DECLARE
l_clob CLOB;
l_file BLOB;
l_dest_offset PLS_INTEGER := 1;
l_src_offset PLS_INTEGER := 1;
l_lang_ctx PLS_INTEGER := dbms_lob.default_lang_ctx;
l_blob_warn PLS_INTEGER;
BEGIN
-- Get clob
l_clob := functionReturningClob(i_code => :P1_CODE, i_type => :P1_TYPE);
-- Create blob
DBMS_LOB.CREATETEMPORARY(l_file, true);
DBMS_LOB.CONVERTTOBLOB(l_file, l_clob, dbms_lob.lobmaxsize, l_dest_offset, l_src_offset, dbms_lob.default_csid, l_lang_ctx, l_blob_warn);
-- Download blob
OWA_UTIL.MIME_HEADER('text/html', false);
HTP.P('Content-Length: ' || dbms_lob.getlength(l_file));
HTP.P('Content-Disposition: attachment; filename="content.html"');
OWA_UTIL.HTTP_HEADER_CLOSE();
WPG_DOCLOAD.DOWNLOAD_FILE(l_file);
END;
With this out of the way, I can call this on demand when I want. For my purposes I've got on my page - Javascript Execute when Page Loads, which contains following code.
// Start the process called HTML and add the following page items as parameter
var p = apex.server.process('HTML', {
pageItems:['P1_CODE', 'P1_TYPE']
}, {
dataType: 'html'
});
// When the process is done, replace the region HTML with the downloaded HTML source
// Also - the region on the page has the "region" as its static ID
p.done(function(data) {
$('#region').html(data);
});
This should give you enough information to make your own adjustments and make it work.

How to paste the text copied in clipboard through Selenium and Java on MacOS

I want to paste some text in one of the textbox in MACOS. I am trying below code. But Control + v and Command + v both are not working. I have also seen that this is known issue, but not sure if it is resolved or not.
https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/5919
The code is as below.
public void copyToClipbord(String copyTo)
{
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection str = new StringSelection(copyTo);
clipboard.setContents(str, null );
}
// And paste into required input/testfield/testarea field object
public void pasteText(WebElement element, String value)
{
copyToClipbord(value);
element.click();
//new Actions( driver ).contextClick( element ).sendKeys( "P" ).sendKeys("\n").perform();
element.sendKeys(Keys.CONTROL, "V");
}
I have also tried context click, that also does not work. I have validated that copyToClipboard function is working properly. Please suggest me, if there are any work around to this.
Thanks,
Umang
You have to select paste option in pop up which open after right and then click on paste option.
You can write code like this.
new Actions(driver ).contextClick(element).sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).
sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).perform();
For me Paste option is present at 5th position. So I have written sendKeys(Keys.ARROW_DOWN) 5 times. You can write this as per your requirement.
I hope this will work for you.
As you have mentioned copyToClipboard() function is working properly moving forward to send the character sequence through sendKeys() you can use the following solution:
import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
copyToClipbord(value);
String data = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor);
element.sendKeys(data);
public String copyFromClipboard() {
boolean found = false
String data = ''
int count = 0
while (found == false) {
count++
try {
WebDriver driver = DriverFactory.getWebDriver()
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard()
data = ((Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor)) as String)
if (!(data.contains('https'))) {
found = false
} else {
println((('Found the data in the ' + count) + ' try: ') + data)
return data
found = true
break
}
}
catch (UnsupportedFlavorException e) {
println(e)
}
catch (IOException e) {
println(e)
}
}
}

RadAsyncUpload file validation fails

I am using RadAsyncControl but my file validation is failing i have tried to track the issue through this example .. so my scenario says
Wrong file size!
However i have set MaxFileSize property to 20971520
and the file being chosen is 1kb .txt file (notepad)
Here's my code
<telerik:RadAsyncUpload ID="rauEvidenceDocuments" runat="server" AllowedFileExtensions=".doc, .docx, .pdf, .txt. .rtf, .pages, .odt, .ppt, .pptx, .png" MultipleFileSelection="Automatic"
OnClientFileSelected="onClientFileSeleted" OnClientFileUploadFailed="OnClientFileUploadFailed" OnClientValidationFailed="validationFailed" RenderMode="Lightweight" MaxFileSize="20971520">
</telerik:RadAsyncUpload>
function validationFailed(radAsyncUpload, args) {
var $row = $(args.get_row());
var erorMessage = getErrorMessage(radAsyncUpload, args);
var span = createError(erorMessage);
$row.addClass("ruError");
$row.append(span);
//alert('validation failed');
}
function getErrorMessage(sender, args) {
var fileExtention = args.get_fileName().substring(args.get_fileName().lastIndexOf('.') + 1, args.get_fileName().length);
if (args.get_fileName().lastIndexOf('.') != -1) {//this checks if the extension is correct
if (sender.get_allowedFileExtensions().indexOf(fileExtention) == -1) {
return ("This file type is not supported.");
}
else {
return ("This file exceeds the maximum allowed size" /*+ sender._maxFileSize()*/);
}
}
else {
return ("not correct extension.");
}
}
function createError(erorMessage) {
var input = '<span class="ruErrorMessage">' + erorMessage + ' </span>';
return input;
}
P.S. It is a multiselect control
Heyy, so i found the issue it was giving me the wrong reason for validation. i had spaces in AllowedFileExtensions that's what was causing validation to fail.
So Cheers after wasting 2 hrs :)

Is there a way to get a node that the cursor is in?

Is there a way to get the node that the cursor or mouse is in?
In the following image the cursor is inside the head tag (meta.tag.tag-name.xml)
The method that I'm looking for would return all the text from "<head>" to toe, I mean, "</head>". Or maybe it would return the node object inside a hierarchy of objects.
In the same example if you put the cursor inside the CSS "html, body" brackets the method would return:
html, body {
height:100%;
}
or
{
height:100%;
}
There is no built in method to do this. But jumtoMatching function does something similar https://github.com/ajaxorg/ace/blob/v1.2.0/lib/ace/editor.js#L2021.
I think you can modify it to return the range instead of selecting it.
ace.on("create", function(e) {
var editor = e.editor;
var ace = editor.ace;
ace.on("mousemove", function(ev) {
//LIMITS the numbers of characters per function search to 30
var line = ev.editor.getSelectedText();
if (letter != line && line != ""&& line.length < 50){
console.log(line);
letter = line;
}
});
}, plugin);

how to Display the Image From Database and Display In View in MVC3?

Hi All i have a FileUpload Control where users can upload Images and Doc files and i am saving the Url of the Path in My Database
now when i am retrieving the data from database i want to check wether the file is .doc or image if it is Doc it will open the file my problem is how do i do it for Image how can i check wether its a image And i have to show the image in a image control never worked on image controls in MVC3
here is my Controller Code
public ActionResult ViewAttachments(string AttachmentName)
{
try
{
AttachmentName = Session["AttachmentUrl"].ToString();
var fs = System.IO.File.OpenRead(Server.MapPath(" "+ AttachmentName+" "));
return File(fs, "application/doc", AttachmentName);
}
catch
{
throw new HttpException(404, "Couldn't find " + AttachmentName);
}
}
i am using an aspx page here What html i have to use and what is the Code i have to change here any suggestion please
What you could do is a simple check on the extension and either return the FILE result as you are doing or a partial view which holds a simple image control.
To expand on your code you could do something like this:
public ActionResult ViewAttachments(string AttachmentName)
{
try
{
AttachmentName = Session["AttachmentUrl"].ToString();
var fs = System.IO.File.OpenRead(Server.MapPath(" " + AttachmentName + " "));
var ext = Path.GetExtension(fs.Name);
switch (ext)
{
case "doc":
return File(fs, "application/doc", AttachmentName);
case "jpg":
case "jpeg":
case "png":
return PartialView("_imgControl", "http://www.mysite.com/downloads/" + AttachmentName + ext);
}
}
catch
{
throw new HttpException(404, "Couldn't find " + AttachmentName);
}
}
Then on your partial view you could just return the model object (in this case the url of the image path on your site) to a standard html image control.

Resources