We use an option set to change the URL of an iFrame. We are getting occasional errors that there are extra spaces in the URL.
Original Code: --- I modified the URL's to keep private, but this code works. (Note it is using Xrm.Page)
function SetDocumentFrame(){
//Get the value of an option set attribute
var personid = Xrm.Page.data.entity.attributes.get("do_personid").getValue();
var value = Xrm.Page.data.entity.attributes.get("do_appreg_recordreviewtype").getValue();
var newTarget = "";
//Set the target based on the value of the option set
switch (value) {
case 1: //Document
newTarget = "https://1.cgi?person_id=" personid "&output_style=p";// Removes the extra characters on the end.
break;
case 2: //Academic Record Summary (RECSUM)
newTarget = "https://1.cgi?person_id=" personid "&output_style=p" "&foo=";
break;
case 3: // Work Experience (GS08)
newTarget = "https://1.cgi?person_id=" personid "&output_style=p" "&foo=";
break;
case 4: //Exams
newTarget = "https://1.cgi?person_id=" personid "&output_style=p" "&foo=";
break;
case 5: //GS02 Application
newTarget = "https://1.cgi?person_id=" personid "&output_style=p" "&foo=";
break;
case 6: //GS02 Letters
newTarget = "https://1.cgi?person_id=" personid "&output_style=p" "&foo=";
break;
default:
newTarget = "https://sample.com//WebResources/docreviewdefault";
break;
}
//Get the default URL for the IFRAME, which includes the
// query string parameters
var IFrame = Xrm.Page.ui.controls.get("IFRAME_reviewframe");
var Url = IFrame.getSrc();
// Capture the parameters
var params = Url.substr(Url.indexOf("?"));
//Append the parameters to the new page URL
newTarget = newTarget params;
// Use the setSrc method so that the IFRAME uses the
// new page with the existing parameters
IFrame.setSrc(newTarget);
}
Thinking that the extra space may be related to the API used. We changed to use the getFormContext (Client API reference) and attempted to trim for the extra spaces.
New Code:
function SetDocumentFrame(executionContext){ var formContext = executionContext.getFormContext(); var personid = formContext.getAttribute("do_personid").getValue(); var value = formContext.getAttribute("do_appreg_recordreviewtype").getValue(); var newTarget = ""; //Set the target based on the value of the option set switch (value) { case 1: newTarget = `https://1.cgi?person_id=${personId}`.trim() break; case 2: newTarget = `https://2.cgi?person_id=${personId}`.trim() break; case 3: newTarget = `https://3.cgi?person_id=${personId}`.trim() break; case 4: newTarget = `https://4.cgi?person_id=${personId}`.trim() break; case 5: newTarget = `https://5.cgi?person_id=${personId}`.trim() break; case 6: newTarget = `https://6.cgi?person_id=${personId}`.trim() break; default: newTarget = `https://./WebResources/websitemessage.html`.trim(); break; } //Get the default URL for the IFRAME, which includes the // query string parameters var IFrame = formContext.ui.controls.get("IFRAME_reviewframe"); var Url = IFrame.getSrc(); // Capture the parameters var params = Url.substr(Url.indexOf("?")); //Append the parameters to the new page URL newTarget = newTarget params; // Use the setSrc method so that the IFRAME uses the // new page with the existing parameters IFrame.setSrc(newTarget); }
QUESTIONS:
1. Is this the correct way to trim?
2. We are thinking that the Xrm.Page may be causing spaces, but when I run using getFormContext. I get an error: Cannot read property 'getFormContext' of undefined. Why?
3. How do I modify the line : var IFrame = Xrm.Page.ui.controls.get("IFRAME_reviewframe"); to use the new API method? Is this right? var IFrame = formContext.ui.controls.get("IFRAME_reviewframe");
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156