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 :
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

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 74 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 31 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans