Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Wednesday, April 3, 2024

Dynamics 365 CE: Call Xrm.WebApi using asynchronous call (async and await)

The following code can be used to call Xrm.Webapi using async and await.


function assignIndustryToContact(executionContext){
    var formContext = executionContext.getFormContext();    
    var accountId = formContext.getAttribute("parentcustomerid").getValue();

    if (accountId != null){
        getIndustryName(executionContext);              
    }
}

async function getIndustryName(executionContext){
    var formContext = executionContext.getFormContext();  
    var accountId = formContext.getAttribute("parentcustomerid").getValue();
    var accountIdGUID = accountId[0].id;    
    let industry = await Xrm.WebApi.retrieveRecord("account", accountIdGUID, "?$select=name,industryid");  
     
    if (industry._igl_industryid_value != null){
        let industryName = await Xrm.WebApi.retrieveRecord("igl_industry", industry.industryid, "?$select=name");
        formContext.getAttribute("fieldName").setValue(industryName.name);
    }  
}


Regards,

Arun S Keerthi

Monday, March 25, 2024

Dynamics 365 CE: Set a field visible using JavaScript

The following JavaScript code can be used to make a field Visible in Dynamics 365 app. 


function showField(executionContext){
    var formContext = executionContext.getFormContext();

    var attributename = formContext.getAttribute("attributename");

    if (attributename == true){
        formContext.getControl("attributename1").setVisible(false);
    }

}