Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Save form name on custom field

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi,

I have 3 main forms in the account entity. I also have a custom field called "form name" in each form. How can I save the form name to the custom field? It doesn't matter whether its onload or onsave. Does anyone have the javascript function for the same?

Thanks in advance. 

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Save form name on custom field

    Thanks so much. It works now!

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Save form name on custom field

    One more thing please make sure you are opening the same form in which you have entered this code. In your case you need to out this code in all three forms.

  • Verified answer
    Syed Ibrahim Profile Picture
    Syed Ibrahim 6,257 on at
    RE: Save form name on custom field

    Try to see are you getting the form name in alert

    function SetFormName(){

    debugger;

    var formName = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();

    alert(formName);

    Xrm.Page.getAttribute("new_customField").setValue(formName );

    }

    Note:I have tested its working fine.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Save form name on custom field

    Put an alert line to check whether issue is in your function or some other script. Please debug the code.

  • Suggested answer
    manojd  Profile Picture
    manojd 1,397 on at
    RE: Save form name on custom field

    Just cross check that you have published your new web resource

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Save form name on custom field

    Yes Ive done it like so:

    Screen-Shot-2017_2D00_11_2D00_24-at-5.27.49-PM.png

    Screen-Shot-2017_2D00_11_2D00_24-at-5.27.49-PM.png

    Screen-Shot-2017_2D00_11_2D00_24-at-5.27.54-PM.png

  • manojd  Profile Picture
    manojd 1,397 on at
    RE: Save form name on custom field

    Hope you are calling SetFormName function onSave of Form control in properties

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Save form name on custom field

    These are the steps I followed but it doesn't seem to work.. Am i doing something wrong here? Excuse me I'm a rookie at the moment. 

    First I went to form properties

    Screen-Shot-2017_2D00_11_2D00_24-at-5.11.59-PM.png

    Then I clicked on add in form libraries 

    Screen-Shot-2017_2D00_11_2D00_24-at-5.11.27-PM.png

    Then I created a new web resource 

    Screen-Shot-2017_2D00_11_2D00_24-at-5.11.41-PM.png

    Then I entered the following info 

    Screen-Shot-2017_2D00_11_2D00_24-at-5.11.59-PM.png

    Then I wrote the following code 

    Screen-Shot-2017_2D00_11_2D00_24-at-5.12.14-PM.png

    Finally I saved and published everything.

    However it doesnt seem to work... 

    Please help. Thanks in advance. :)

  • Suggested answer
    Syed Ibrahim Profile Picture
    Syed Ibrahim 6,257 on at
    RE: Save form name on custom field

    Call the below JS on Save or onChange

    function SetFormName(){

    var formName = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();

    Xrm.Page.getAttribute("new_customField").setValue(formName );

    }

    Hope this works

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Save form name on custom field

    Use below line to get current form name.

    Xrm.Page.ui.formSelector.getCurrentItem().getLabel();

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans