Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Form customisation

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 Microsoft Employee 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,832 Super User 2024 Season 1 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,832 Super User 2024 Season 1 on at
    RE: Form customisation

    Hi Prajwal Bhetwal,

    You have created 3 duplicate posts. Please delete them.

    Thanks,

    Girish S.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans