On you CRM form, add an event for the Result Approved field, and call it resultApprovedOnChange
- Double click on the field in form designer, click on events and add the event. Make sure you have added the JavaScript library that will contain the code
- Add the following code to the JavaScript library. Replace the field names as required:
function resultApprovedOnChange()
{
var resultApproved = Xrm.Page.getAttribute("new_resultapproved").getValue();
if (resultApproved == true)
{
var userId = Xrm.Page.context.getUserId();
var username = Xrm.Page.content.getUserName();
// If you username field is a lookup field use the following code
var lookupData = new Array();
var lookupItem = new Object();
lookupItem.id = userId;
lookupItem.name = username;
lookupItem.entityType = "systemuser";
lookupData[0] = lookupItem;
Xrm.Page.getAttribute("new_resultapprovedlastupdatename").setValue(lookupData);
// If you username field is a text field
Xrm.Page.getAttribute("new_resultapprovedlastupdatename").setValue(username);
var currentDateTime = new Date();
Xrm.Page.getAttribute("new_resultapprovedlastupdatedate").setValue(currentDateTime);
}
else if (resultApproved == false)
{
}
}
Update your web resource JavaScript file, and Publish.
* Please note that comment above based on the username field. Code is different if field is lookup or field is single line of text (string).