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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Insert the data of modified on field in another text field

(0) ShareShare
ReportReport
Posted on by 958

I need to display the modified on in another text field which is multiple lines text field using javascript.

Criteria is there are two fields first is, option set in which has true and false and second is, multiple lines of text.

So using javascript i need to display the modified on data  into second field when the value of first field is selected as yes.

And it can be run every time, so in the second text field add the new data of that time modified on into second field with previous one.

So, can anyone help me to do this using javascript?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hello Shakti,

    Try to write like below -

    function onChangeOptionSet()
    {
    
        // Get Option Set Value 
        var isCheck =  Xrm.Page.getAttribute("FieldNAme").getValue();
        if(isCheck)
        {
            //Retrieve the modified on value  using current record id 
            var recordid =Xrm.Page.data.entity.getId();       
            var modifiedon = null;
            var name = null;
    
            var req = new XMLHttpRequest();
            req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts("+recordid+")?$select=modifiedon,name", true);
            req.setRequestHeader("OData-MaxVersion", "4.0");
            req.setRequestHeader("OData-Version", "4.0");
            req.setRequestHeader("Accept", "application/json");
            req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
            req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
            req.onreadystatechange = function() {
                if (this.readyState === 4) {
                    req.onreadystatechange = null;
                    if (this.status === 200) {
                        var result = JSON.parse(this.response);
                        modifiedon = result["modifiedon"];
                        name = result["name"];
                        //Set field value 
                        Xrm.Page.getAttribute("MiltilineTextFieldName").setValue(modifiedon);
    
                    } else {
                        Xrm.Utility.alertDialog(this.statusText);
                    }
                }
            };
            req.send();
        }
    
    
    }


  • ashlega Profile Picture
    34,477 on at

    Hi,

     I would think you need an onsave javascript that would be doing this:

       var isCheck =  Xrm.Page.getAttribute("FieldName").getValue();

       if(isCheck)

       {

            var d = new Date();

    var currentValue = Xrm.Page.getAttribute("MiltilineTextFieldName").getValue();

    Xrm.Page.getAttribute("MiltilineTextFieldName").setValue(currentValue + "\n" +  d.toString());

       }

      Although, maybe I'd rather have that done in a workflow/plugin..

  • Shakti Singh Rajput Profile Picture
    958 on at

    This is the code that i am recently used but it gives script error, so what can i do?

    function onSave()
    {

    // Get Option Set Value
    var isCheck = window.parent.Xrm.Page.getAttribute("new_caseesclated").getValue();
    alert(isCheck);
    if(isCheck == yes)
    {
    alert("insdie if");
    //Retrieve the modified on value using current record id

    var d = new Date();

    var currentValue = window.parent.Xrm.Page.getAttribute("new_escalatedblog").getValue();

    window.parent.Xrm.Page.getAttribute("new_escalatedblog").setValue(currentValue + "\n" + d.toString());

    }
    }

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    6,211 on at

    Hi Sakti,

    Please remove window.parent and try.

    Thanks,

    Shahbaaz

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans