Populate a Catalog Item variable from its corresponding Universal Task short description

Basim
Tera Contributor

Scenario:

A catalog item is available for completion on the portal when a Universal Task has a Type = Submit Catalog Item.

 

Basim_0-1750951789099.png

 

 

Challenge:

Populate the asset name variable (with the asset's display name) from the Universal Task's short description.

 

Basim_1-1750951789108.png

 

 

1 REPLY 1

Sanjay191
Tera Sage

Hello @Basim 

  • You pass the Short Description of a Universal Request.

  • You extract the asset name (like #274753 HP ProBook x360 435 69) from that description using regex.

  • You return the extracted name as an output variable from the Custom Action.

  • You can use this variable later in the Flow Designer.


    Please use the below script in custom action

    var inputString = "Guardian Form -#274753 HP ProBook x360 435 \n69-Sietse Radix";

    // i just considering as string(hardcode) but you can dynamically handle this by input parameter in custom action  like input.inputString  // variable that you are using
    var regex = /-(#\d+\s[\s\S]*?)\s*-[A-Za-z]+\s[A-Za-z]+/;
    var match = inputStr.match(regex);

    if (match && match[1]) {
    var assetName = match[1].trim();

    return output.asstName // output variable.
    gs.info("Asset Name: " + assetName);
    } else {
    gs.info("Asset name not found.");
    }


and also take help from the below article as well to update catalog item variables.


https://www.servicenow.com/community/servicenow-ai-platform-articles/set-value-of-a-catalog-variable...

https://www.servicenow.com/community/developer-forum/changing-the-type-of-existing-catalog-item-vari...


If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Thank you !!