Incident to It General Request

ofekg
Tera Contributor

the demand is:
Button to convert an incident into a generic request form (Generic Request)
Fields to be filled automatically:
Requested for {will be populated with the caller field}
Please describe how we can help you {will be populated with the description field}
short description, assignment group , assigned to will be filled in the same way.
Priority = low
State = open
Task Type= Catalog Task

this is my script in the ui action which not working well, need help to fix my script so it will work -

(function executeAction(current, gForm, gS) {
    // Verify the sys_id of the catalog item
    var catalogItemSysId = '<sys_id של Generic Request>'; // Replace with the actual sys_id of the Generic Request catalog item
    if (!catalogItemSysId) {
        gs.addErrorMessage('Catalog Item sys_id is missing. Please update the script with the correct sys_id.');
        return;
    }

    // Create a new RITM record
    var ritm = new GlideRecord('sc_req_item');
    ritm.initialize();

    // Link to the catalog item
    ritm.cat_item = catalogItemSysId;

    // Populate fields based on the Incident
    if (current.caller_id) ritm.requested_for = current.caller_id;
    if (current.short_description) ritm.short_description = current.short_description;
    if (current.assignment_group) ritm.assignment_group = current.assignment_group;
    if (current.assigned_to) ritm.assigned_to = current.assigned_to;

    ritm.priority = 4; // Priority = Low
    ritm.state = 1;    // State = Open

    // Custom field example (replace with your field name)
    ritm.u_task_type = 'catalog task';

    // Ensure variables exist before populating
    ritm.variables = {}; // Initialize variables if needed
    if (current.description) {
        ritm.variables.please_describe_how_can_we_help_you = current.description;
    }

    // Save the RITM
    var ritmSysId = ritm.insert();
    if (!ritmSysId) {
        gs.addErrorMessage('Failed to create the Requested Item (RITM).');
        return;
    }

    // Success message for the user
    gs.addInfoMessage('Incident has been converted to a Generic Request. RITM Number: ' + ritmSysId);

    // Redirect to the new RITM record
    action.setRedirectURL('/sc_req_item.do?sys_id=' + ritmSysId);

})(current, gForm, gs);





1 REPLY 1

Uncle Rob
Kilo Patron

When you say "not working well", what does that mean specifically?
That helps us isolate where the problem might be, vs deconstructing your entire script from scratch.