Get Data of submitted RITM's Multi Row Variable Set

WaseemM
Giga Expert

Hi All,

 

I have a catalog with Muti Row variable set, I want the information stored in the multi row variable set of submitted RITM. I can extract this information using flow designer's get catalog variable action but I want to get this using PowerShell RESTAPI.

I've tried using below code but I'm not able to get the values from it.

 

$instance = "https://servicenow.com"
$snowuser = "user"
$snowpassword = "password"
$ritmNumber = "RITMXXXXXXX"

# Authentication setup
$pair = "${snowuser}:${snowpassword}"
$encodedAuth = [Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$headers = @{
    Authorization  = "Basic $encodedAuth"
    "Content-Type" = "application/json"
    Accept         = "application/json"
}

# Get RITM sys_id
$ritmUrl = "$instance/api/now/table/sc_req_item?sysparm_query=number=$ritmNumber&sysparm_fields=sys_id"
$ritmResponse = Invoke-RestMethod -Uri $ritmUrl -Headers $headers -Method Get
$ritmSysId = $ritmResponse.result.sys_id

# Get MRVS sys_id from sc_item_option_mtom
$mtomUrl = "$instance/api/now/table/sc_item_option_mtom?sysparm_query=request_item=$ritmSysId"
$mtomResponse = Invoke-RestMethod -Uri $mtomUrl -Headers $headers -Method Get
1 ACCEPTED SOLUTION

I used it for Form variables. I think it is not working for MRVS. Now, only possible option is to access "Multi Row Question Answers" table:

User the Below URL: 

https://<instance>.service-now.com/api/now/table/sc_multi_row_question_answer?sysparm_query=parent_id%3D<sys_idof RITM>&sysparm_display_value=true&sysparm_exclude_reference_link=true&sysparm_fields=item_option_new%2Cvalue%2Crow_index&sysparm_limit=10

In your code I noticed that you have RITM number. If you don't have sys_id of RITM, then run the API already shared to get the sys_id and then use this api for MRVS.

This API returns each variable as separate line. Eg it you MRVS has 5 variable and you have 2 rows then this returns 10 record.

row_index value from the return JSON will give you the particular row number. It will be same for all the variables in a particular row and it is a random integer. Use this row to identify the row and then take variables value from each entries 

 

Thank you,
Palani

View solution in original post

5 REPLIES 5

palanikumar
Mega Sage

Hi,

You can get the variable details from sc_req_item directly. Refer the below code

$ritmUrl = "$instance/api/now/table/sc_req_item?sysparm_query=number=$ritmNumber&sysparm_fields=sys_id,variables.mrvs_internal_name" 
// Replace mrvs_internal_name with actual MRVS Internal Name
Thank you,
Palani

$ritmUrl = "$instance/api/now/table/sc_req_item?sysparm_query=number=$ritmNumber&sysparm_fields=sys_id,variables.server_details"
$ritmResponse = Invoke-RestMethod -Uri $ritmUrl -Method Get -Headers $headers
$ritmResponse.result

Variable Set.png

 

I've tried it but it's simply returning the RITM's sysid.

I used it for Form variables. I think it is not working for MRVS. Now, only possible option is to access "Multi Row Question Answers" table:

User the Below URL: 

https://<instance>.service-now.com/api/now/table/sc_multi_row_question_answer?sysparm_query=parent_id%3D<sys_idof RITM>&sysparm_display_value=true&sysparm_exclude_reference_link=true&sysparm_fields=item_option_new%2Cvalue%2Crow_index&sysparm_limit=10

In your code I noticed that you have RITM number. If you don't have sys_id of RITM, then run the API already shared to get the sys_id and then use this api for MRVS.

This API returns each variable as separate line. Eg it you MRVS has 5 variable and you have 2 rows then this returns 10 record.

row_index value from the return JSON will give you the particular row number. It will be same for all the variables in a particular row and it is a random integer. Use this row to identify the row and then take variables value from each entries 

 

Thank you,
Palani

Ankur Bawiskar
Tera Patron
Tera Patron

@WaseemM 

1 way is to create a scripted REST API and you can get the details in 1 endpoint itself by passing RITM number

How to fetch Multirow variables on RITM/SCTASK using REST api 

you can't get it directly using RITM Table API

1) 1st get the RITM sysId using number etc

2) then use Table API on Multi Row Question Answer [sc_multi_row_question_answer] with parent_id=RITM SysId

Old thread where I shared the approach

Access multi-row variable set from RITM using Rest API explorer 

Example below

AnkurBawiskar_0-1749127163823.png

 

AnkurBawiskar_1-1749127163821.png

 

AnkurBawiskar_2-1749127164130.png

 

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader