web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Issue in switching between the Tabs In the form

(0) ShareShare
ReportReport
Posted on by 3
////
This is my form. When I create a New communication and click on the tab Risk Assessment which has a iframe, redirects back the communication I created, its not only for the communication but also for Notes and Documents as well. When I create a Notes and click Risk Assessment it redirects back to the notes I created. Below is my Web resource code, When the debugger is on its working properly
 
function redirectURL(executionContext,iFrameName){
debugger;
var IFrame = Xrm.Page.ui.controls.get(iFrameName);
var Url = IFrame.getSrc();
var userId = RemoveBrackets(parent.Xrm.Utility.getGlobalContext().userSettings.userId);
      var req = new XMLHttpRequest();
      req.open(/GET/, parent.Xrm.Page.context.getClientUrl() + /api/data/v9.1/contacts?$select=contactid,_uph_uphuser_value&$filter=_uph_uphuser_value eq / + userId + //, false);
      req.setRequestHeader(/OData-MaxVersion/, /4.0/);
      req.setRequestHeader(/OData-Version/, /4.0/);
      req.setRequestHeader(/Accept/, /application/json/);
      req.setRequestHeader(/Content-Type/, /application/json; charset=utf-8/);
      req.setRequestHeader(/Prefer/, /odata.include-annotations=///*////);
      req.onreadystatechange = function () {
        if (this.readyState === 4) {
          req.onreadystatechange = null;
          if (this.status === 200) {
            var results = JSON.parse(this.response);
            for (var i = 0; i < results.value.length; i++) {
              var contactid = results.value[i][/contactid/];
              var _uph_uphuser_value = results.value[i][/_uph_uphuser_value/];
              var _uph_uphuser_value_formatted = results.value[i][/_uph_uphuser_value@OData.Community.Display.V1.FormattedValue/];
              var _uph_uphuser_value_lookuplogicalname = results.value[i][/_uph_uphuser_value@Microsoft.Dynamics.CRM.lookuplogicalname/];
              var parameter1 = generateToken();
                            CreateRecord(contactid, parameter1);
                            if (parent.Xrm.Page.context.getQueryStringParameters().TreeData !== undefined) {
                            if (Url.indexOf(/?/) !== -1)
                            {
                              Url = Url.substr(0, Url.indexOf(/?/));
                            }
                            var param1 = Url+ /?Data=/+parent.Xrm.Page.context.getQueryStringParameters().TreeData+ /&Token=/ + parameter1;
                                IFrame.setSrc(param1);
                          }
                            
                            else{                            
                
                IFrame.setSrc(Url + /&Token=/ + parameter1);
              }
            }
          } else {
            parent.Xrm.Utility.alertDialog(this.statusText);
          }
        }
      };
      req.send();
 
}
function generateToken() {
             var tokenLength = 20;
      var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
      var token = '';
      for (var i = 0; i < tokenLength; i++) {
        var randomIndex = Math.floor(Math.random() * characters.length);
        token += characters.charAt(randomIndex);
      }
      return token;
}     
function CreateRecord(contactid, parameter1) {
      debugger;
      var entity = {};
      entity[/uph_ContactId@odata.bind/] = //contacts(/ + contactid + /)/;
      entity.uph_name = parameter1;
      var req = new XMLHttpRequest();
      req.open(/POST/, parent.Xrm.Page.context.getClientUrl() + /api/data/v9.1/uph_uphtokenauthorizes/, true);
      req.setRequestHeader(/OData-MaxVersion/, /4.0/);
      req.setRequestHeader(/OData-Version/, /4.0/);
      req.setRequestHeader(/Accept/, /application/json/);
      req.setRequestHeader(/Content-Type/, /application/json; charset=utf-8/);
      req.onreadystatechange = function () {
        if (this.readyState === 4) {
          req.onreadystatechange = null;
          if (this.status === 204) {
            var uri = this.getResponseHeader(/OData-EntityId/);
            var regExp = ///(([^)]+)//)/;
            var matches = regExp.exec(uri);
            var newEntityId = matches[1];
          } else {
            parent.Xrm.Utility.alertDialog(this.sstatusText);
          }
        }
      };
      req.send(JSON.stringify(entity));
    }
function RemoveBrackets(guid) {
      if (IsValidValue(guid))
        return guid.replace(/[{}]/g, '');
      return null;
    }
    function IsValidValue(value) {
      if (value === undefined || value === null || value === // || value === /undefined/ || value === /null/)
        return false;
      return true;
    }
function redirectPageToSearch()
{
    debugger;
console.log(/Before getting extraqsValue/ + parent.Xrm.Page.context.getQueryStringParameters());
console.log(/extraqsValue: / + parent.Xrm.Page.context.getQueryStringParameters().TreeData);
     if (parent.Xrm.Page.context.getQueryStringParameters().TreeData !== undefined) {
        // // Get the value of the 'extraqs' parameter
         var extraqsValue = parent.Xrm.Page.context.getQueryStringParameters().TreeData;
         Xrm.Page.ui.tabs.get(/Search Resources/).setFocus();
         Xrm.Page.ui.tabs.get(/Search Resources/).setDisplayState(/expanded/);
    // // Log the value to the browser console
         console.log(/extraqs value: / + extraqsValue);
     } else {
        console.log(/extraqs parameter not found in the URL./);
     }
}
I have the same question (0)
  • Suggested answer
    Dengliang Li Profile Picture
    Microsoft Employee on at
    Hi,
     
    Can you explain the purpose of your WebResource?
    Your last function redirectPageToSearch(), this function is not called.
     
    Best Regards,
    Dengliang Li
     
  • CU27040858-5 Profile Picture
    3 on at
    the webresource will get the url and attach the contact id to the iframe url and make the request redirectURL() function in the web resource will do this function. but the redirectPageToSearch() is called in the onload event.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
11manish Profile Picture

11manish 151

#2
ManoVerse Profile Picture

ManoVerse 149 Super User 2026 Season 1

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 66 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans