Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
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

Posted on by 25

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);
}
}

Categories:
  • Suggested answer
    Pradeep Rai Profile Picture
    Pradeep Rai 5,490 Super User 2024 Season 2 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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,558 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,647 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans