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

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

how to get a multi select security role GUID in another field when it is selected in one field with a comma using Jscript?

(0) ShareShare
ReportReport
Posted on by 5

5265.png

I have the same question (0)
  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at
    RE: how to get a multi select security role GUID in another field when it is selected in one field with a comma using Jscript?

    Hi,

    Try below code on onchange of security role multi select field...

    function SecurityRoleOnChange(executionContext) {

    var formContext = executionContext.getFormContext();

    var roleConfiguration='';

    //Returns Array of Selected OptionSet Text: ["One", "Two","Six"]

    var selectedTexts = formContext.getAttribute("cr127_securityrole").getText();

    var businessUnit=formContext.getAttribute("cr127_businessunit").getValue();

    var buId=null;

    if(businessUnit!=null)

    {

    buId=businessUnit[0].id;

    }

    buId=buId.replace('{','').replace('}','');

    for(var i=0;i<selectedTexts.length;i++)

    {

    Xrm.WebApi.online.retrieveMultipleRecords("role", "?$select=roleid&$filter=(name eq '"+selectedTexts[i]+"' and _businessunitid_value eq "+buId+")").then(

    function success(results) {

    console.log(results);

    for (var i = 0; i < results.entities.length; i++) {

    var result = results.entities[i];

    // Columns

    var roleid = result["roleid"]; // Guid

    roleConfiguration=roleConfiguration+roleid+",";

    formContext.getAttribute("cr127_roleconfiguration").setValue(roleConfiguration);

    }

    },

    function(error) {

    console.log(error.message);

    }

    );

    }

    }

  • Divyamahanthi Profile Picture
    5 on at
    RE: how to get a multi select security role GUID in another field when it is selected in one field with a comma using Jscript?

    Ok Thanks thats working

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 241

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 164 Super User 2025 Season 2

#3
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 153

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans