Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Business Unit Specific New Contact Form

(0) ShareShare
ReportReport
Posted on by 267

Hi,

I'm looking at creating a Form  (New Contact) which will display different fields / requirements depending on the Business Unit it is assigned to.  I already have a New Contact form for an existing Business Unit that I don't want to remove

I've looked at older blogs  Business Unit Specific Custom Forms - Microsoft Dynamics CRM Forum Community Forum but I'm still having issues?

I've carried out the steps mentioned in the above post.

New Security Role - Contact Form (Veterans Members Only)  

pastedimage1674209422654v2.png

New Business Unit created -  Veterans Services 

pastedimage1674209346944v1.png


Created a New Form

pastedimage1674209722086v3.png

Assigned the New from to the Security Role

pastedimage1674209799063v4.png

Ok and even published the customizations

Assigned myself the Security role, but I'm still seeing the existing New contact Form??

What Security permission would I need to give?

Currently these are them

pastedimage1674209997213v5.png

pastedimage1674210045099v6.png


  • Verified answer
    Pradeep Rai Profile Picture
    5,487 Super User 2025 Season 1 on at
    RE: Business Unit Specific New Contact Form

    Yes Please.

    I am happy to help you.

    Have a good time.

  • Chris1968 Profile Picture
    267 on at
    RE: Business Unit Specific New Contact Form

    Hi,

    I think it works??

    pastedimage1674818087232v1.png

    It's asking for the last name as soon as the New button is selected but that's not a bad thing....

    Did have some issues when closed the app down and re-opened ???

    I'll give it a bit more testing but thank you for all your help.  If I do have any further issues with this,  will it be ok to reach out to you again??

  • Pradeep Rai Profile Picture
    5,487 Super User 2025 Season 1 on at
    RE: Business Unit Specific New Contact Form

    Yes. Please copy new one and Pass execution context during function call as shown below:

    pastedimage1674816949796v1.png

  • Chris1968 Profile Picture
    267 on at
    RE: Business Unit Specific New Contact Form

    Hi,

    Changed the function description

    pastedimage1674815195361v1.png

    Now get an error (Error log provided)  I have saved and published

    pastedimage1674815329034v2.png

    So not confuse this error was for the previous code not the one you have recently updated..

    Can I just copy this new one it to the Form Libraries with the edit function??

  • Pradeep Rai Profile Picture
    5,487 Super User 2025 Season 1 on at
    RE: Business Unit Specific New Contact Form

    Hi,

    Please call function as shown below:

    pastedimage1674815429748v1.png

    and updated the code little:

    function getAssignedTeam(executionContext)
    {
      var formContext=executionContext.getFormContext();  
     var userSettings = Xrm.Utility.getGlobalContext().userSettings;
      var currentUserId=userSettings.userId;  
    
     var fetchXML="?fetchXml=" 
        "" 
            "" 
            "" 
            "" 
            "" 
            "" 
            "" 
                "" 
                    "" 
                        "" 
                    "" 
                "" 
            "" 
        "" 
    "";
    
     Xrm.WebApi.retrieveMultipleRecords("team", fetchXML).then(
        function success(result) {
           var lookupValue = new Array();
           lookupValue[0] = new Object();
           lookupValue[0].id = result.entities[0].teamid;
           lookupValue[0].name = result.entities[0].name;
           lookupValue[0].entityType = "team";                      
     formContext.getAttribute("ownerid").setValue(lookupValue);
    formContext.data.entity.save();
        },
        function (error) {
            console.log(error.message);
    // handle error conditions
        }
    );
    }


    Above code will work 100%

  • Pradeep Rai Profile Picture
    5,487 Super User 2025 Season 1 on at
    RE: Business Unit Specific New Contact Form

    pastedimage1674814766206v1.png


  • Chris1968 Profile Picture
    267 on at
    RE: Business Unit Specific New Contact Form

    Hi,

    Sorry should have mentioned, I've done those steps

    pastedimage1674814377783v1.png

    pastedimage1674814427466v2.png

    pastedimage1674814450343v3.png

    But my name still appears as the Owner??

    pastedimage1674814530835v4.png

  • Suggested answer
    Pradeep Rai Profile Picture
    5,487 Super User 2025 Season 1 on at
    RE: Business Unit Specific New Contact Form

    In above code you do not have to change anything.

    You need to create one js. file and add them as webresource in dynamic crm.

    After that go to contact form and under form editor you will find form properties there you can register onload event and in onload call above function as described below 

    www.tutorialspoint.com/.../microsoft_crm_jscript_web_resources.htm

  • Chris1968 Profile Picture
    267 on at
    RE: Business Unit Specific New Contact Form

    Hi,

    Sorry if I'm being a bit naïve here but I'm assuming it's like any script, I work a little with PowerApps you I will need to change some of the script?

    Such as these attribute names??

    "<attribute name='name'/>"+

    "<attribute name='businessunitid'/>"+

    "<attribute name='teamid'/>"+

    "<attribute name='teamtype'/>"+

    "<order attribute='name' descending='false'/>"+

  • Suggested answer
    Pradeep Rai Profile Picture
    5,487 Super User 2025 Season 1 on at
    RE: Business Unit Specific New Contact Form

    Hi,

    Please use below code on form load.

    function getAssignedTeam(executionContext)
    {
      
      var formContext=executionContext.getFormContext();
    
      var userSettings = Xrm.Utility.getGlobalContext().userSettings;
      var currentUserId=userSettings.userId;
    
      var fetchXML="?fetchXml=" 
    	"" 
    		"" 
    		"" 
    		"" 
    		"" 
    		"" 
    		"" 
    			"" 
    				"" 
    					"" 
    				"" 
    			"" 
    		"" 
    	"" 
    "";
    
    Xrm.WebApi.retrieveMultipleRecords("team", fetchXml).then(
        function success(result) {
           
           var lookupValue = new Array();
           lookupValue[0] = new Object();
           lookupValue[0].id = result.entities[0].teamid;
           lookupValue[0].name = result.entities[0].name;
           lookupValue[0].entityType = "team";                 
    
         formContext.getAttribute("ownerid").setValue(lookupValue);
        },
        function (error) {
            console.log(error.message);
            // handle error conditions
        }
    );
     
    }


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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,217 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,978 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans