Skip to main content
Dynamics 365 general forum
Suggested answer

Form customisation

editSubscribe (0) ShareShare
ReportReport
Posted on by 65

Hi,

I'm adding a JS to the CRM form that should do 3 things: 

1. Should hide an option set value (180560002) while creating a new record. 

2. Should hide option set value from the existing record if the option set value != 180560002, to prevent users from updating it to that option.

3. Should show the option set value if the record already exists in CRM for value = 180560002.

Currently, my JS is doing the first two things correctly but it is also clearing the option set value from the record that already exists with contact type = 180560002

pastedimage1663301041235v1.png

  • Suggested answer
    Community Member Profile Picture
    Community Member UG Leader on at
    RE: Form customisation

    Hi Prajwal Bhetwal,

    Amira Beldjilali's answer is correct.

    To get a field's value, please use formContext.getAttribute("boq_contacttype").getValue();

    attribute.getValue (Client API reference) - Power Apps | Microsoft Docs

    So your code should be like this:

    function removeOption(executionContext)
    {
    	var formContext = executionContext.getFormContext();
    	var contacttype = formContext.getControl("boq_contacttype");
    	var contacttypevalue = formContext.getAttribute("boq_contacttype").getValue();
    	var formtype = formContext.getFormType();
    	
    	if(formtype == 1){
    		contacttype.removeOption(180560002);
    	}else if(formtype == 2 || formtype == 3){
    		if(contacttypevalue != 180560002){
    			contacttype.removeOption(180560002)
    		}
    	}
    }

  • Suggested answer
    RE: Form customisation

    Hello,

    You need to get the value of the attribute to compare

    docs.microsoft.com/.../getvalue

    Regards,

    Amira

  • GirishS Profile Picture
    GirishS 27,799 Super User on at
    RE: Form customisation

    You can only delete a post you made if there has been no reply. So keep this post and delete remaining 3 other posts.

    Thanks,

    Girish S.

  • Prajwal Bhetwal Profile Picture
    Prajwal Bhetwal 65 on at
    RE: Form customisation

    under action I can only see edit and report.. how do i delete it?

  • GirishS Profile Picture
    GirishS 27,799 Super User on at
    RE: Form customisation

    Hi Prajwal Bhetwal,

    You have created 3 duplicate posts. Please delete them.

    Thanks,

    Girish S.

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,045 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,570 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans