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

  • Suggested answer
    necsa Profile Picture
    3,455 on at
    RE: Javascript Xrm.Page.data.save().then saves, but next save reverts changes.

    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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 91

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 78 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans