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

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

formContext.data.attributes returns null when trying to retrieve form parameters passed through another form

(0) ShareShare
ReportReport
Posted on by

as MS will deprecated Xrm.Page.context.getQueryStringParameters, i am trying to switch it to formContext.data.attributes as MS suggested. but after doing the following, i am not able to get the passed parameter:

1. add the parameter to the form property

pastedimage1597954377667v1.png

2.  js code open form with this parameter value passed:

var entityFormOptions = {};
entityFormOptions["entityName"] = "new_privatesalenotice";

var formParameters = {};
formParameters["new_bypassprivatesalenoticereason"] = "test";

// Open the form.
Xrm.Navigation.openForm(entityFormOptions, formParameters);

3. read value on form load:

var onLoad = function (executionContext) {
var formContext = executionContext.getFormContext();
if (formContext.data.attributes.get("new_bypassprivatesalenoticereason") !== null) // sample code for getting non-entity bound data
{
Xrm.Navigation.openAlertDialog({ text: formContext.data.attributes.get("new_bypassprivatesalenoticereason").getValue() }); // This will show the alert "Test parameter value"
}};

but i am getting formContext.data.attributes null error. 

anyone has an idea? thanks a lot!

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at
    RE: formContext.data.attributes returns null when trying to retrieve form parameters passed through another form

    HI,

    Can you try below code and see if it works?

    var firstName = formContext.getAttribute("firstname").getValue();

    docs.microsoft.com/.../clientapi-form-context

    Field value is getting set on new form?

    Also try adding settimeout.

    carldesouza.com/.../

    Please mark my answer verified if i were helpful

  • Community Member Profile Picture
    on at
    RE: formContext.data.attributes returns null when trying to retrieve form parameters passed through another form

    hi there, i am trying to pass the parameter from one form to another, not setting up the field value.

    formContext.getAttribute("firstname").getValue(); is working, but that's for getting the field value on the from. thanks~

  • cloflyMao Profile Picture
    25,210 on at
    RE: formContext.data.attributes returns null when trying to retrieve form parameters passed through another form

    Hi Ruonan,

    Try to debug your code with debugger, I followed your steps and the code works for me.

    Please check whether you had missed anything carefully.

    1. I have a custom entity Country, add parameter(SafeString) to form properties.

    2. Run the function at OnLoad event of Country form.

    3. In Contact form, open Country form by executing function Xrm.Navigation.openForm

    var entityFormOptions = {};
    entityFormOptions["entityName"] = "new_country";
    
    var formParameters = {};
    formParameters["custom_param"] = "Clofly";
    
    Xrm.Navigation.openForm(entityFormOptions, formParameters);

    4. Debugging:

    Everything goes well

    pastedimage1597993671146v1.png

    Or you could try formContext.getAttribute("your attribute name") !== null

    Regards,

    Clofly

  • Community Member Profile Picture
    on at
    RE: formContext.data.attributes returns null when trying to retrieve form parameters passed through another form

    hi Clofly,

    thanks for the reply. i am working on the CRM Online instead of on-premise, not sure if that matters.

    i debug the code and here is what i saw. you can see formContext.data.attributes is null. 

    pastedimage1598050177286v1.png

    pastedimage1598050231424v2.png

    here is the code i am opening the form:

    pastedimage1598050298086v3.png

    and here is the parameter on the form property:

    pastedimage1598050348445v4.png

    thank you very much!

  • cloflyMao Profile Picture
    25,210 on at
    RE: formContext.data.attributes returns null when trying to retrieve form parameters passed through another form

    Hi Ruonan,

    Could you teach me how to run function in your format?

    As per my understanding, did you execute BFC.PrivateSaleNotice.onLoad function at OnLoad event of form?

    By imitating your format, I was only able to run cloflyutils.test, but I don't know how to run onload inside the cloflyutils.test

    (I have tried following formats and they all failed to be executed, xxx is not defined in web resource.

    cloflyutils.test.onload 

    onload

    )

    var cloflyUtils = cloflyUtils || {};
    
    cloflyUtils.test = (function () {
      console.log(123);
      var onload = function (executionContext) {
        var formContext = executionContext.getFormContext();
        if (formContext.data.attributes.get("custom_param") !== null) {
          console.log(formContext.data.attributes.get("custom_param").getValue());
        }
      }
    
    })

    It seems that you're modifying a system js and adding your custom code to it, however, the executionContext might be different in system js library, thus there was no entity context in formContext.data.

    If above would be your situation, you could create a new js library and run a simple format function

    function xxx() {

    }

    at OnLoad event of form to test whether it could work.

    Regards,

    Clofly 

  • Community Member Profile Picture
    on at
    RE: formContext.data.attributes returns null when trying to retrieve form parameters passed through another form

    hi Clofly,

    thanks for the reply. here is what i am doing.

    on the form property, i am setting up the function will be calling while form onload. i need to check "Pass execution context as first parameter" so i have value of   var formContext = executionContext.getFormContext();    

    pastedimage1598374789092v1.png

    pastedimage1598374823840v2.png

    i am wondering when you refer the test function in your case, how you pass the parameter "executionContext". i might miss something since i am still new to CRM online customization. thank you in advance!

  • cloflyMao Profile Picture
    25,210 on at
    RE: formContext.data.attributes returns null when trying to retrieve form parameters passed through another form

    Hi Ruonan,

    It seems that function format of the JS library is complicated, I can see it involves closure, it might had affected the executionContext.

    I tried to reproduce your issue with function in anonymous format, however, I am still not able to run function in such format xxx.yyy.zzz.

    var cloflyUtils = cloflyUtils || {};
    
    cloflyUtils.test = (function () {
        
        var onLoad = function (executionContext) {
            debugger;
            var formContext = executionContext.getFormContext();
            if (formContext.data.attributes.get("custom_param") !== null) {
                console.log(formContext.data.attributes.get("custom_param").getValue());
            }
        }
        return onLoad;
    })()
    
    var OnLoad = cloflyUtils.test;

    To invoke onLoad function of cloflyUtils.test, I return it at the end of cloflyUtils.test, then assign it to a new variable, but the function to be executed at OnLoad event of form need to be OnLoad instead.

    pastedimage1598424787258v1.png

    Anyway, I can still get formContext.data.attributes 

    pastedimage1598424936688v2.png

    and the formContext contains entity information of current form.

    pastedimage1598425014503v3.png

    It would be helpful for me if you could share me full code of your js library, then I will able to investigate your code and functions in depth.

    Or you could just create a new blank js file to run your own logic, a simple function call might works compared with complex namespace.

    Regards,

    Clofly
     

  • Community Member Profile Picture
    on at
    RE: formContext.data.attributes returns null when trying to retrieve form parameters passed through another form

    hi Clofly,

    thanks for the reply. i tried another custom entity called "new_repo", which on the js i am not using the name space, but still not seeing anything for the data.attributes

    here is my new_repo form property:

    pastedimage1598466594761v2.png

    pastedimage1598466617208v3.png

    pastedimage1598466644125v4.png

    here is my new_repo form js. the function is called on the new_repo entity from loaded. so when the formContext.ui.getFormType() === 2, which is edit mode, i will open a new new_repo from with parameters "bypass_reason", the the form with be opened in the create mode with parameter passed.

    pastedimage1598466685367v5.png

    here is the js debugger result. you can see formContext.data.attributes is null. any ideas? thank you!

    pastedimage1598466369349v1.png

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at
    RE: formContext.data.attributes returns null when trying to retrieve form parameters passed through another form

    Hi Ruonan,

    I think I had found reason of the issue.

    Did you run the code in legacy web client

    e.g: I opened quick create form of my custom entity in legacy web client and then encountered you issue.

    Also, formContext.data.attributes is null.

    3326.PNG

    It is because that executionContext in legacy web client and UCI is different, hence name space is not the reason actually and you can still use it.

    If above would be your situation, then please switch to UCI, the legacy web client will be deprecated in October.

    Regards,

    Clofly

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: formContext.data.attributes returns null when trying to retrieve form parameters passed through another form

    hi Clofly,

    i am running this code  in the CRM online, not on-premise; but you are right, i am running the code in legacy web client instead of Unified interface. we will work on the unified UI conversion next after on-premise  to online upgrade. thank you for looking into this for me. really appreciate it. i will test it again after converting to unified interface then.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 235

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 177

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 156 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans