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)

pass field name as a parameter to get value of field

(0) ShareShare
ReportReport
Posted on by

hi

I have a date field I want to use across many forms and I do a date check off number of days

and I check multiple fields on the date form

I created a javscript to do the date check and I want to know if you can pass the field name as a parameter and then use get value as you see below

var datefield = Xrm.Page.getAttribute(attributename).getValue();

 

I pass the attribute name which is the one of many names of the fields on the form

 

so I want to know if I can pass a field name and get the  value of it dynamically rather then explicitly call the field in the phone

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    Can you clarify what you mean by getting the value dynamically? If you mean that you would like to recycle the line of JavaScript, what you can do is define another string variable and pass it in to the parameter. But this is making it unnecessarily complicated.

    It is better to define and get each field invidually:

    var datefield1 = Xrm.Page.getAttribute(attributename1).getValue();

    var datefield2 = Xrm.Page.getAttribute(attributename2).getValue();

  • Suggested answer
    Community Member Profile Picture
    on at

    I use several date fields on many forms  I created jscript to do validations on the dates

    I thought I could pass in the name of the field I want to check on the form to get the value and then run it against checking the date

    I have to explicitly name the field in js

    I so your saying to pass the field into a variable so if the field is not on that particular form it will bypass it?

  • Community Member Profile Picture
    on at

    Hi,

    You can check if the field is not on a form like this:

    var ABC= Xrm.Page.getAttribute("your_attribute_name").getValue();

        if (ABC != null) {

     }

    Again, you would need to do this for each of the fields and so I recommend putting a check in a JScript function. I also like to add another condition in case the field exists but is empty:

    var ABC= Xrm.Page.getAttribute("your_attribute_name").getValue();

        if (ABC != null && ABC != "") {

                    }

  • Suggested answer
    Community Member Profile Picture
    on at

    I'm sorry, my previous comment is incorrect. Try this:

    var ABC= Xrm.Page.getAttribute("your_attribute_name");    

         if (ABC != null) {

    //run your code

                   }

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