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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Open different form when opening related entity form , from different entities

(0) ShareShare
ReportReport
Posted on by

Hi everyone!

I have the Service Activities related with both Cases and Projects . I want when i open a Service Activity from Projects form , to open a different Service Activity form than when opening through the Cases Form.

Is there a way to achieve this?

Thanks!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Somesh2207 Profile Picture
    1,563 on at

    Hi Shak,

    This can be done using Form Script. On load of the Case form, you need to write a function which does the following:

    1. Get the entity type code of the entity from which the current record was opened. Fortunately CRM javascript allows that
    2. Based on the entity type code, you can write script to Navigate or reload using Particular form based on Form name.

    22sep_5F00_2.png

    See the below Javascript that I used, and tested that it is working:

    function FormNavigate(){
    
        /// Set form names
    var ProjectServiceActivityForm = "Service Activity - Project";
    var CaseServiceActivityForm = "Service Activity - Case";
    
    // Logic to identify if the record is opened from Project or Case
    var qsparam = Xrm.Page.context.getQueryStringParameters();
    
    var parentEntityId = qsparam["_CreateFromType"];
    var lblForm = "";
    if(parentEntityId == 112) /// If parent entity is Case etc - 112 for case
    {
        lblForm = CaseServiceActivityForm;
    }
    else if (parentEntityId == 10064) /// if parent entity is Project 
    {
        lblForm = ProjectServiceActivityForm;
    }
    
    /// Code to Navigate to form using Form Name
     if(lblForm){   
                    //check if the current form is form need to be displayed based on the value
        if (Xrm.Page.ui.formSelector.getCurrentItem().getLabel() != lblForm) {
            var items = Xrm.Page.ui.formSelector.items.get();
            for (var i in items) {
                var item = items[i];
                var itemId = item.getId();
                var itemLabel = item.getLabel()
                if (itemLabel == lblForm) {
                    //navigate to the form
                    item.navigate();
                } //endif
            } //end for
        } //endif
    }
    }
    You can get the entity type code (etc used in the code above) from the Metadata browser or by opening URL of any record, you can get it using the etc query param like below screenshot for case record. Similarly you can get for Project as well:
    22sep_5F00_2.png 

    Mark this as Verified Answer if it resolves your issue

  • Community Member Profile Picture
    on at

    Thanks but it doesn't work.

    It detects the correct form the code , but when i open the Service Activity it still uses the default one instead the other one i use in my code.

  • Suggested answer
    Somesh2207 Profile Picture
    1,563 on at

    Hi Shak,

    Can you please ensure you are using the correct form names. In the above code sample, I gave the dummy names. You need to change the form name as per your system.

    /// Change the names as you have in your system

    var ProjectServiceActivityForm = "Service Activity - Project";
    var CaseServiceActivityForm = "Service Activity - Case";
    


    Thanks

  • Community Member Profile Picture
    on at

    Actually it worked after making a few changes on the code. However now i get prompted each time to save any unsaved changes which is not desirable. I think i will not use this workaround and think of something else

  • Somesh2207 Profile Picture
    1,563 on at

    Hi Shak,

    I am sure the changes which I suggested has nothing to do with the unsaved changes. And please note this is not a workaround or unsupported customization. It is perfectly supported and I am using the same code for my client which is being used in production.

    You can try something else if you want. But please review your form scripting which is causing the issue that you are facing with unsaved changes. 

    And do post the solution if you find any other alternative. Thank you

  • Community Member Profile Picture
    on at

    Thanks for the information

    Basically the issue is that when the form loads it already populates some fields and then navigates/changes to the new form. When it goes there i get a popup to save any unsaved changes or discard the changes. Is there a way to bypass this popup and navigate to the new form without the warning?

  • Somesh2207 Profile Picture
    1,563 on at

    Hi Shak,

    Before I proceed I wanted to point out how CRM forms work - It is stored by User's last time activity.

    If User opens a record and sees "Form A", and chooses to navigate to "Form B", then CRM notes it and when the user is back on record next time or even in next session, Form B will be opened by default.

    This is CRM's behavior and cannot be changed. 

    With that said,

    this is what you can try:

    1. Can you move the function of navigation (the above one) as the first function, even before the other script which sets some value. This may work, but need to test
    2. Is it Ok to save the data first before navigating to other form. You can programatically save the record and then call the Form Navigating code. 

    Form save programatically - 

    Xrm.Page.data.save().then(function(){console.log('Success Callback')},function(){console.log('Error Callback')});


    let me know if the above solution works for you

  • D365Sgreen Profile Picture
    20 on at

    Now that xrm.page is deprecated I'm new to this and trying to replace it with formContext and getting nowhere fast. WOuld you mind helping me by updating this valuable info with that new method?

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans