Creating Ritm Based on String filed value

vishalAg20
Tera Contributor

Hi All,
Around one requirement we need to create ritm based on string filed value like user can add multi user ids on this filed 

(hr234;hr235;hr236), based on particular hr id create separate ritm for each Hr id.

So How can I achieve this requirement and Please help me on this.

Thank you

1 ACCEPTED SOLUTION

Deepak Shaerma
Kilo Sage

Hi @vishalAg20 
you can use Business Rule or Flow Designer as well for the requirement.
Create a business rule
Apply to Service Catalog Request [sc_request] or Service Catalog Item [sc_req_item]), based on where you’re capturing the user IDs.
When to run: After Insert or After Update (According to your convinience)

// Assuming ā€˜user_ids_field’ is the field that holds the ID string
    var userIds = current.user_ids_field.toString();
    var idsArray = userIds.split(';');
    
    idsArray.forEach(function(id) {
        // Logic to create a RITM for each ID
        var ritmGR = new GlideRecord('sc_req_item');
        ritmGR.initialize();
        ritmGR.short_description = "RITM for HR ID: " + id; // Customize based on your requirements
        // Set other necessary fields
        ritmGR.insert();
    });


Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ā€Œā€Œ
Thanks & Regards 
Deepak Sharma 

View solution in original post

6 REPLIES 6

Deepak Shaerma
Kilo Sage

Hi @vishalAg20 
you can use Business Rule or Flow Designer as well for the requirement.
Create a business rule
Apply to Service Catalog Request [sc_request] or Service Catalog Item [sc_req_item]), based on where you’re capturing the user IDs.
When to run: After Insert or After Update (According to your convinience)

// Assuming ā€˜user_ids_field’ is the field that holds the ID string
    var userIds = current.user_ids_field.toString();
    var idsArray = userIds.split(';');
    
    idsArray.forEach(function(id) {
        // Logic to create a RITM for each ID
        var ritmGR = new GlideRecord('sc_req_item');
        ritmGR.initialize();
        ritmGR.short_description = "RITM for HR ID: " + id; // Customize based on your requirements
        // Set other necessary fields
        ritmGR.insert();
    });


Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ā€Œā€Œ
Thanks & Regards 
Deepak Sharma 

Thanks For Reply
How to call Business rule in Workflow Can I create Script include for using same code.

 

Script include requires additional steps and information that can be passed further and call from workflows or business rules later

Deepak Shaerma
Kilo Sage

Hi @vishalAg20 
You cannot call business rules in workflow directly. You can achieve the effect of reusing the logic in both contexts Workflows(workflow scripts) by encapsulating the logic within a Script Include. 
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ā€Œā€Œ
Thanks & Regards 
Deepak Sharma