Map<String,String> buildVariablesMap(String requestItemNumber) {
def limitResult = 20
def Map<String,Object> result = [:]
def response
// lookup all options associated to this number
response = httpClient.get("/api/now/table/sc_item_option_mtom?sysparm_query=request_item.number=${requestItemNumber}&sysparm_limit=${limitResult}")
if (!response || !response.result) return null // ignore if there are no results
// For each of the options, lookup corresponding question and add to the result map
response.result.each {
def optionSysId = it.sc_item_option?.value
def optionDetails = httpClient.get("/api/now/table/sc_item_option/${optionSysId}")
if (!optionDetails || !optionDetails.result) return // ignore - the option itself is not found
def itemOptionNew = optionDetails?.result?.item_option_new?.value
if (!itemOptionNew) return // ignore - link to question not found
def itemOptionNewDetails = httpClient.get("/api/now/table/item_option_new/${itemOptionNew}")
if (!itemOptionNewDetails || !itemOptionNewDetails.result) return // ignore - the question is not found
def value1
if(itemOptionNewDetails.result.question_text.equals("List of Reviewers?"))
{
def allref=optionDetails.result.value
String[] str
def allEmail=[]
str = allref.split(',')
for( String s : str )
{
allEmail.add(nodeHelper.getReference("sys_user", "sys_id", s)?.email)
}
value1=allEmail.join(",")
}
else
{
value1=optionDetails.result.value
}
result.put ( itemOptionNewDetails.result.question_text,value1)
}
return result
}
if(entity.tableName == "sc_req_item") {
replica.key = entity.key
replica.summary = entity.short_description
replica.description = entity.description
replica.attachments = entity.attachments
replica.comments = entity.comments
replica.state = entity.state
replica.variables = buildVariablesMap(entity.key)
}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.