Resolve all button Issue

priya pretty
Tera Contributor

Hi Experts,

 

I have written the below code for resolving the records based on the Vulnerability. when ever I click on the resolve all button only that record is getting closed but not the other records. Can anyone help with this.

 

Thanks in advance

function onClickResolveall() {
    sn_vul.Modal.popupResolveAppItemModal();

    var relatedItems = new GlideRecord('sn_vul_app_vulnerable_item');
    relatedItems.addQuery('vulnerability', current.vulnerability);
    relatedItems.addEncodedQuery('active=true^stateIN1,2');
    relatedItems.query();

    while (relatedItems.next()) {
        relatedItems.state = 101; // Resolved state
        relatedItems.resolution_reason = current.resolution_reason;
        relatedItems.active = false;
        relatedItems.update();
    }
    action.setRedirectURL(current);
}

 

5 REPLIES 5

Vrushali  Kolte
Mega Sage

Hi @priya pretty ,

Can you try moving the encoded query above the addquery ?

 

If my answer solves your question please mark it as Helpful 👍🏻 and Accepted

Hi @Vrushali Kolte , 

 

I have tried but it is not working, not sure what is missing 😞 

Aman Kumar S
Kilo Patron

Hi @priya pretty ,

Try chagning your code 1 line, since you are dot walking the while loop is ending up iterating the same object hence closing closing only current record, also try to add some logs in your query to erify if your query is returing multiple records.

   relatedItems.resolution_reason = current.getValue("resolution_reason");

 

Best Regards
Aman Kumar

Hi @Aman Kumar S ,

 

I have tried it, but only one record is getting closed 😞