sc_task under ritm with variables

outgoing snow
Map<String, String> buildVariablesMap(String requestItemNumber) {
    def limitResult = 20

    def Map<String, Object> result = [:]
    
    
    // lookup all options associated to this number
    
    def optionList = httpClient.get("/api/now/table/sc_item_option_mtom?sysparm_query=request_item.number=${requestItemNumber}&sysparm_limit=${limitResult}")    
    if (!optionList || !optionList.result) return null  // ignore if there are no results
    
    
    // For each of the options, lookup corresponding question and add to the result map
    optionList.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
        
        
        result.put ( itemOptionNewDetails.result.question_text, optionDetails.result.value)        
    }

    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)

}


if(entity.tableName == "sc_task") {
    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
    
    // the variables are in the containing requestItem, which is stored in request_item
    if (entity.request_item?.display_value) {
     
        replica.variables      = buildVariablesMap("RITM0010075") 
        //entity.request_item?display_value
        replica.variables      = buildVariablesMap(entity.request_item?display_value) 

}


}
Map<String, String> buildVariablesMap(String entityNumber) {
    def Map<String, Object> result = [:]
 
 
    // lookup all options associated to this number
 
    def optionList = httpClient.get("/api/now/table/sc_item_option?sysparm_query=^!JOINsc_item_option.sys_id=sc_item_option_mtom.sc_item_option!^JOINsc_item_option_mtom.request_item=sc_req_item.sys_id!sys_id=e6f7defedb5e2010073c6693ca961940&sysparm_display_value=true&sysparam_fields=item_option_new,value")
    if (!optionList || !optionList.result) return null  // ignore if there are no results
 
 
    // For each of the options, lookup corresponding question and add to the result map
    optionList.result.each {
        if(it.value.toString().isEmpty()) return
 
        result.put(it.item_option_new.display_value, it.value)
    }
 
    return result
 
}