Regarding Catalog item

Ravichandra2
Tera Contributor

How can i Create SCcatalog tasks based on the Catalog Item variables. For Example

When Request Type = New VDI
Catalog Task would be created and Assigned to AMER ITSD  and
When Request Type = Configuration Change | IF RAM <= 16GB AND Disk <= 120GB AND CPU <= 3
Catalog Task would be created and Assigned to Endpoint Engineering (Client Engg.)
 
Please Help me on this
6 REPLIES 6

Ratnakar7
Mega Sage
Mega Sage

Hi @Ravichandra2 ,

 

To create Service Catalog (SC) catalog tasks based on Catalog Item variables and conditions, you can use Catalog Client Scripts in ServiceNow. These scripts allow you to dynamically generate and configure catalog tasks based on the user's selections and conditions.

Here's an example script based on your requirements:

// Get the selected request type and variables
var requestType = g_form.getValue('request_type');
var ram = parseFloat(g_form.getValue('ram'));
var disk = parseFloat(g_form.getValue('disk'));
var cpu = parseFloat(g_form.getValue('cpu'));

// Define the catalog task assignment group
var assignmentGroup = '';

// Check the request type and variables to determine the assignment group
if (requestType == 'New VDI') {
    assignmentGroup = 'AMER ITSD'; // Set the assignment group for New VDI
} else if (requestType == 'Configuration Change' && ram <= 16 && disk <= 120 && cpu <= 3) {
    assignmentGroup = 'Endpoint Engineering'; // Set the assignment group for Configuration Change
}

// Create the catalog task if an assignment group is specified
if (assignmentGroup) {
    var catalogTask = new GlideRecord('sc_task');
    catalogTask.initialize();
    catalogTask.cat_item = current.sys_id; // Set the catalog item reference
    catalogTask.assignment_group.setDisplayValue(assignmentGroup); // Set the assignment group
    catalogTask.insert();
}

 

Thanks,

Ratnakar

Thank You very much @Ratnakar7 

Amit Gujarathi
Giga Sage
Giga Sage

HI @Ravichandra2 ,
I trust you are ding great.
Please find below script for the same.

(function executeRule(current, previous /*null when async*/) {

    // Function to create a catalog task
    function createCatalogTask(assignmentGroup, shortDescription) {
        var task = new GlideRecord('sc_task');
        task.initialize();
        task.short_description = shortDescription;
        task.assignment_group.setDisplayValue(assignmentGroup);
        task.request_item = current.sys_id;
        task.insert();
    }

    // Check for New VDI request type
    if (current.variables.request_type == 'New VDI') {
        createCatalogTask('AMER ITSD', 'Task for New VDI request');
    }

    // Check for Configuration Change request type with conditions
    else if (current

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Hi @Amit Gujarathi 

I am completed some steps using flow designer but some thing for values i am not able to give the conditions like less than and greater than on it

 

Thanks and Regards

ravichandra