We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Get Data of submitted RITM's Multi Row Variable Set

WaseemM
Tera 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

Hi Ankur,

 

Thanks for your support. I've tried this already. I was able to get the field information not the values of submitted RITM.