How to mark catalog task as closed complete

taqdeer
Tera Contributor

Hello All,

I have a catalog item where it creates 5 catalog tasks in it based on the path variable.

Path Variable :
Fast Track  : Value - 1
Full Track   : Value - 2

Tasks based on the short description :

Task 1 : Initial Assessment
Task 2 : GAO Review
Task 3 : Security Review
Task 4 : Update IT Technology
Task 5 : Procurement Review

I also have a UI action "convert to Full Track". When this UI action is clicked then currently a new RITM is created with all the previously selected information. However, when this UI action is clicked I want to set few values as default for the  "Initial Assessment" task. 

Below are the ones that I want to set them by default.
Path Variable on the sc_task level : Full Track : Value - 1
State on the sc_task : Closed Complete

Could any one please help me on this. I am sharing you the script that is written on UI Action. Please help me with the modifications to it.

//Add cancel block for existing ticket.

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);

var item = cart.addItem('0f7a48959763d51c6f73baa3f153af13', 1);

cart.setVariable(item, "generic_flow_var_requested_for_all", current.parent.requested_for);
cart.setVariable(item, "generic_flow_var_requested_for", current.parent.requested_for);
cart.setVariable(item, "generic_flow_var_requested_for_lm", current.parent.requested_for);

cart.setVariable(item, "requested_for", current.parent.variables.requested_for);
cart.setVariable(item, "formatter", current.parent.variables.formatter);
cart.setVariable(item, "formatter2", current.parent.variables.formatter2);

cart.setVariable(item, "please_select_the_questioner_that_will_be_submitted_with_this_request", current.parent.variables.please_select_the_questioner_that_will_be_submitted_with_this_request);
cart.setVariable(item, "please_attach_the_questionnaire", current.parent.variables.please_attach_the_questionnaire);
cart.setVariable(item, "riso_approval", current.parent.variables.riso_approval);

cart.setVariable(item, "itisc_leader_approval", current.parent.variables.itisc_leader_approval);
cart.setVariable(item, "formatter3", current.parent.variables.formatter3);
cart.setVariable(item, "formatter4", current.parent.variables.formatter4);

cart.setVariable(item, "it_technology_owner_consent", current.parent.variables.it_technology_owner_consent);
cart.setVariable(item, "formatter5", current.parent.variables.formatter5);
cart.setVariable(item, "formatter6", current.parent.variables.formatter6);

cart.setVariable(item, "formatter7", current.parent.variables.formatter7);
cart.setVariable(item, "formatter8", current.parent.variables.formatter8);
cart.setVariable(item, "formatter9", current.parent.variables.formatter9);

cart.setVariable(item, "formatter10", current.parent.variables.formatter10);
cart.setVariable(item, "formatter11", current.parent.variables.formatter11);
cart.setVariable(item, "formatter12", current.parent.variables.formatter12);

cart.setVariable(item, "formatter13", current.parent.variables.formatter13);
cart.setVariable(item, "formatter16", current.parent.variables.formatter16);
cart.setVariable(item, "eurofins_employees", current.parent.variables.eurofins_employees);

cart.setVariable(item, "eurofins_externals", current.parent.variables.eurofins_externals);
cart.setVariable(item, "customers", current.parent.variables.customers);
cart.setVariable(item, "publicly_available", current.parent.variables.publicly_available);

cart.setVariable(item, "formatter17", current.parent.variables.formatter17);
cart.setVariable(item, "formatter14", current.parent.variables.formatter14);
cart.setVariable(item, "formatter15", current.parent.variables.formatter15);

cart.setVariable(item, "formatter18", current.parent.variables.formatter18);
cart.setVariable(item, "formatter19", current.parent.variables.formatter19);
cart.setVariable(item, "formatter20", current.parent.variables.formatter20);

cart.setVariable(item, "formatter21", current.parent.variables.formatter21);
cart.setVariable(item, "formatter22", current.parent.variables.formatter22);
cart.setVariable(item, "contract_group_level", current.parent.variables.contract_group_level);

cart.setVariable(item, "formatter23", current.parent.variables.formatter23);
cart.setVariable(item, "international_contract", current.parent.variables.international_contract);
cart.setVariable(item, "formatter24", current.parent.variables.formatter24);

cart.setVariable(item, "formatter25", current.parent.variables.formatter25);
cart.setVariable(item, "formatter26", current.parent.variables.formatter26);
cart.setVariable(item, "formatter27", current.parent.variables.formatter27);

cart.setVariable(item, "formatter28", current.parent.variables.formatter28);
cart.setVariable(item, "information_classification_c", current.parent.variables.information_classification_c);
cart.setVariable(item, "information_classification_d", current.parent.variables.information_classification_d);

cart.setVariable(item, "formatter29", current.parent.variables.formatter29);
cart.setVariable(item, "formatter30", current.parent.variables.formatter30);
cart.setVariable(item, "formatter31", current.parent.variables.formatter31);

cart.setVariable(item, "specify_the_impacted_service_s", current.parent.variables.specify_the_impacted_service_s);
cart.setVariable(item, "formatter32", current.parent.variables.formatter32);
cart.setVariable(item, "specify_the_impacted_application_s2", current.parent.variables.specify_the_impacted_application_s2);
cart.setVariable(item, "group_it_solutions_impact_b", current.parent.variables.group_it_solutions_impact_b);

var rc = cart.placeOrder();
//action.setRedirectURL(current.parent);
var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery("request=" + rc.sys_id);
gr.query();
if (gr.next()) {
    gr.parent = current.parent;
    gr.assignment_group = current.parent.assignment_group;
	gr.work_notes = "This full track request is created from parent "+current.parent.number;
    //gr.assigned_to = current.assigned_to;
    GlideSysAttachment.copy('sc_req_item', current.parent.sys_id, 'sc_req_item', gr.sys_id);
    gr.update();
}

cancelWorkflow(current.parent);
action.setRedirectURL(gr);
gs.flushMessages();
gs.addInfoMessage("New request " + gr.number + " created successfully.");

function cancelWorkflow(ritm) {
//     var wkfw = new Workflow();
//     var context = wkfw.getContexts(ritm);
//     if (context.next()) {
//         var gr = new GlideRecord('wf_context');
//         gr.get(context.sys_id);
//         new Workflow().cancelContext(gr);
//     }

    var gr1 = new GlideRecord("sc_req_item");
    gr1.addQuery("sys_id", ritm);
    gr1.query();
    if (gr1.next()) {
        gr1.state = 4;
        gr1.update();
    }
    var gr2 = new GlideRecord("sc_task");
    gr2.addQuery("parent", ritm);
    gr2.query();
    while (gr2.next()) {
        gr2.state = 4;
        gr2.update();
    }
}
3 REPLIES 3

palanikumar
Mega Sage

Hi,

Where is the UI Action is created. Is the new RITM created successfully?

Thank you,
Palani

Hi Palani,
Yes New RITM is created successfully with all the previously filled details. Now this RITM has Initial Assessment task created I want to set Path variable as "Full track" which has value 1 and state as closed complete.

Please note that I have created a business rule to achieve this However I want to execute this business only when that UI action is clicked.

UI Action : Create Full track request test

Business rule logic : 

When to run condition :
Item is 'x'
short description is Initial assesment
Action : 
State as Closed complete

Hi,

The workflow does not trigger immediately after the RITM is created. It will take few second. So, the code you are using in the above UI Action to update the task will not work.

 

You can create a Business rule for SC Task.

Add below condition in the business rule

Advanced Check box

Check Insert Check Box 

Set the below condition

Requested Item.Parent is not empty 

Add your script to update task in the Advanced tab

palanikumar_0-1695100807886.png

 

 

Thank you,
Palani