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)

Append date value into string field every time field is changed to "yes"

(0) ShareShare
ReportReport
Posted on by

Hi experts,

I have a boolean (yes/no) field named "new_escalated" in the case record. 

Whenever the user changes the field to yes, I would like to append the modified on date & time value into a custom text field called "new_escalationlog" .

How can I append a value onto a text field every time the escalated field is changed to yes? Basically I want to keep an audit log of the field on the record itself.

Thanks,

Jon

*This post is locked for comments

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

    Hi Jon ,

    Are you talking about Dynamics CRM Modified On field value or at the time of on change using javascript you want to get the client machine date time ?

    Seems it will be good if you register a method in onsave and based on field changes (You can check isDirty property)get the current date using javascript and append to your text field .

    To retrieve dynamics CRM modified on field value you need to call WebAPI , however it will give you old value in client side not current date time.

  • Suggested answer
    Swetha Poojary Salaskar Profile Picture
    326 on at

    I would recommend to write plugin on Post operation of on update that case new_escalated field. and their append the modifiedon date in "new_escalationlog"  multiline text field. Also reset the escalated field to No.

    Also remember to check depth in code. So plugin should not run in infinite time.

    Thanks,

    Swetha.

    If found useful, please mark the answer as verified

  • gdas Profile Picture
    50,091 Moderator on at

    I agreed with Swetha  , you can get everything in the plugin post Image  , you just need to set the value to your text box .

  • Community Member Profile Picture
    on at

    Hi Goutam,

    I'd prefer using Javascript instead of plugin because of performance issues.

    Also I dont mind using either CRM Modified On value or client machine time.

    I think taking client machine time would be better because modified on would return inaccurate values.

    Thanks,

    Jon

  • Community Member Profile Picture
    on at

    Hi Swetha,

    Thanks for your reply.

    I'll look into this approach as well.

    Thanks,

    Jon

  • Community Member Profile Picture
    on at

    I have created this code to set the value of the computer time. How can I change my code to append to time to the field, so the previous values are not lost?

    function saveEscalate()
    {
    	var check =  Xrm.Page.getAttribute("new_escalated").getValue();
    	alert(check);
    	if(check == true)
    	{ 
    		alert(check);
    		var today = new Date();
    		var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
    		var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
    		alert(date+" "+time);
    		
    		Xrm.Page.getAttribute("new_escalationlog").setValue(date+" "+time);
    	}
    	else
    	{
    
    	}
    }


    Thanks,

    Jon

  • Suggested answer
    Swetha Poojary Salaskar Profile Picture
    326 on at

    HI Jon,

    you will need to get the value from "new_escalationlog" field and the append and set the value

    example:

    var oldvalue=Xrm.Page.getAttribute("new_escalationlog").getValue();

    var newvalue=oldvalue + " " +date+" "+time;

    Xrm.Page.getAttribute("new_escalationlog").setValue(newvalue);

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Jon ,

    You need to get the value and append with new value with old value like below - Hope this helps.

            function saveEscalate() {            
                var check = Xrm.Page.getAttribute("new_escalated").getValue();
                alert(check);
                if (check == true) {
                    alert(check);
                    var today = new Date();
                    var date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
                    var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
                    alert(date + " " + time);
                    var newValue = date + " " + time;
                    var oldValue = Xrm.Page.getAttribute("new_escalationlog").getValue();             
                    var newValue = oldValue + "\n + " + newValue; // Added new line in the text , you can add any other text as well like oldvalue and new value               
                    Xrm.Page.getAttribute("new_escalationlog").setValue(newValue);
                }
                else {
    
                }
            }


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