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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Javascript Xrm.Page.data.save().then saves, but next save reverts changes.

(0) ShareShare
ReportReport
Posted on by 25

Hi, 

I have two custom fields in the task entity,  Text and Duration. 

When a user fills both fields, I need to save the form (if its in create mode) , create a external record and then clear the fields.

if we open an pre-existing task. it works fine. but if I create  a new task, once the user hits save button. the "duration" comes back to the original number... ?? 

I'm sure my JavaScript talents are the culprit... I have no idea what I am doing wrong. (the text field works fine)

function Tasks_addduration()
{    
    if ((Xrm.Page.getAttribute('new_addtotaskdescription').getValue() != null) && (Xrm.Page.getAttribute('new_addtoduration').getValue() != null)) {         
        if (Xrm.Page.ui.getFormType()==1){
            Xrm.Page.data.save().then(Tasks_createtasklog ,  function(){alert("La creation du Task Log a échoué voir tony");});      
        } else  {  
            alert("no longer in create mode") ;        
            Xrm.Page.getAttribute('new_addtoduration').setValue(null);                                        
            Xrm.Page.getAttribute('new_addtotaskdescription').setValue(null);                    
            Xrm.Page.data.entity.save();
        }        
    }    

    function Tasks_createtasklog()
    {            
        alert("duration! Before Null:"   Xrm.Page.getAttribute('new_addtoduration').getValue().toString()) ;        
        Xrm.Page.getAttribute('new_addtoduration').setValue(null);                    
        Xrm.Page.getAttribute('new_addtotaskdescription').setValue(null);                    
        alert("after nulled")        
    }
}

1614.record.jpg

I have the same question (0)
  • Suggested answer
    necsa Profile Picture
    3,455 on at

    Change line 3 to compare your value with null as below and try it

    if ((Xrm.Page.getAttribute('new_addtotaskdescription').getValue() !== null) && (Xrm.Page.getAttribute('new_addtoduration').getValue() !== null)) {

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 128 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 97

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans