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

Community site session details

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

I have got SelectedControlSelectedItemIds from the main view and want to retrieve and update fields for those Ids. I see the first Id is being skipped

(0) ShareShare
ReportReport
Posted on by 27

Here is my code snippet. First Guid operation is being skipped. Need help

for (var i = 0; i < _dataparams.length; i++) {
var addressId = decodeURIComponent(_dataparams[i]).replace(/\+/g, " ").split("=");
var Guid = addressId.toString();
var checkBox = document.getElementById("chkBox");
var content = document.getElementById("content").value;

if (Guid != "" || Guid != undefined) {
var query = "?$select=homenet_addressstatus";
Xrm.WebApi.retrieveRecord("homenet_address", Guid, query).then(
function success(result) {
var addressStatus = result.homenet_addressstatus;
console.log("address status:" + addressStatus);
if (addressStatus != undefined) {//deactivate record
var entity = {};
entity.statecode = 1;
var entityName = "homenet_address";
console.log("address status and check box value:" + addressStatus, checkBox.checked);
if (addressStatus == 2 && checkBox.checked == true) {
entity.homenet_sendaddresscancelemail = true;
entity.homenet_canceladdressemailcontent = content;
}

Xrm.WebApi.updateRecord(entityName, Guid, entity,
function (output) {
if (output.success) {
console.log("Record updated successfully.");
} else {
console.log("Error in updating record:" + this.statusText);
}
});
console.log("retrieved address status value:" + addressStatus);
}
});
}
else {
console.log("Error in RetriveSingleRecord: " + output.data.message);
}

}

}

catch (e) {
console.log("Error in deactivating address record " + e.message);
}
}

I have the same question (0)
  • Suggested answer
    Pradeep Rai Profile Picture
    5,489 Moderator on at
    RE: I have got SelectedControlSelectedItemIds from the main view and want to retrieve and update fields for those Ids. I see the first Id is being skipped

    Hi,

    Please try below code:

    function ab() {
    
        var condition = "";
        for (var i = 0; i < _dataparams.length; i  ) {
            condition  = ""   _dataparams[i] ""
        }
    
        var fetchXML = ""  
            ""  
            ""  
            ""  
            ""  
            ""  
            condition  
            ""  
            ""  
            ""  
            "";
        Xrm.WebApi.retrieveMultipleRecords("homenet_address", "?fetchXml=" fetchXML).then(
            function success(result) {
                for (var i = 0; i < result.entities.length; i  ) {
                    var currentEnt = result.entities[i];
                    if (currentEnt.homenet_addressstatus != undefined &&
                        currentEnt.homenet_addressstatus == 2 &&
                        checkBox.checked == true) {
                        var entity = {};
                        entity.statecode = 1;
                        entity.homenet_sendaddresscancelemail = true;
                        entity.homenet_canceladdressemailcontent = content;
                        // update the record
                        Xrm.WebApi.updateRecord("homenet_address", currentEnt.homenet_addressid, entity).then(
                            function success(result) {
                                console.log("homenet_address updated");
                               
                            },
                            function (error) {
                                console.log(error.message);
                                // handle error conditions
                            }
                        );
                    }
                }
    
                // perform additional operations on retrieved records
            },
            function (error) {
                console.log(error.message);
                // handle error conditions
            }
        );
    }


    Thanks,
    Pradeep.

    Please mark this as VERIFIED. if it helps.

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 179 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 110

#3
Gerardo Rentería García Profile Picture

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

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans