getting the case number from the incident record

Sathiskumar_D
Giga Sage

Hello,

I would like to get the status of case (opened , closed at, opened by etc) from related list in incident. .

var grCase=new GlideRecord('incident');
grCase.addEncodedQuery('^RLQUERYsn_customerservice_case.incident,>=1^stateNOT IN6,3,7^ENDRLQUERY');
grCase.addQuery('sys_id','<sys_id of the record>' );
grCase.query();
gs.info(grCase.getRowCount());
while(grCase.next()){
	for (var key in grCase) {
			gs.info('Attribute Name : '+key +' Value : '+grCase[key]);
}
}

Any help is greatly appreciated. Thanks 

 

1 ACCEPTED SOLUTION

Vishal Jaswal
Giga Sage

Hello @Sathiskumar_D 

Your Code modified:

var grCase = new GlideRecord('incident');
grCase.addEncodedQuery('^RLQUERYsn_customerservice_case.incident,>=1^stateNOT IN6,3,7^ENDRLQUERY');
grCase.addQuery('sys_id', 'e02a7a6b877313003c1c8467a7cb0bd5');
grCase.query();
gs.info(grCase.getRowCount());
while (grCase.next()) {
    var grCase1 = new GlideRecord('sn_customerservice_case');
    grCase1.addQuery('incident', 'e02a7a6b877313003c1c8467a7cb0bd5');
    grCase1.query();
    while (grCase1.next()) {
        for (var key in grCase1) {
            gs.info('Attribute Name : ' + key + ' Value : ' + grCase1[key]);
        }
    }
}

Screenshot:

vishal_jaswal_1-1741113284543.png

 


Enhanced Code which can be leveraged as fix script to be run via scheduled job:

var grCase = new GlideRecord('incident');
grCase.addEncodedQuery('^RLQUERYsn_customerservice_case.incident,>=1^stateNOT IN6,3,7^ENDRLQUERY');
grCase.query();
gs.info("No. of INCs found: " + grCase.getRowCount());
while (grCase.next()) {
    var grCase1 = new GlideRecord('sn_customerservice_case');
    grCase1.addQuery('incident', grCase.sys_id); // Pass the sys_id dynamically
    grCase1.query();
    while (grCase1.next()) {
        for (var key in grCase1) {
            gs.info('Attribute Name: ' + key + ' Value: ' + grCase1[key]);
        }
    }
}

Screenshot:

vishal_jaswal_2-1741113300424.png

vishal_jaswal_3-1741113325282.png

 

 

 


Hope that helps!

View solution in original post

5 REPLIES 5

AshishKM
Kilo Patron
Kilo Patron

Hi @Sathiskumar_D , 

 

So what's the issue, you already have written some code.

 

//grCase[key] will give the record and you need to use column name with using the dot
gs.info('Attribute Name : '+key +' Value : '+grCase[key].status); // did you try this 

 

-Thanks,
AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Sathiskumar_D
Giga Sage

it doesn't pull the case number details.. not even case number in the related list! 

Sathiskumar_D
Giga Sage

@AshishKM if I add "status" like you mentioned in the comment, I got all values undefined

 

 

Ok .. so grCase[key] is returning the sys_id of that record not the reference

What value is printing without using .state filed, if its sys_id then try to get regferece record of thatsys_id.

 

 

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution