Flow Designer Action and Record Producer

Mansi Motwani1
Tera Contributor

Hi All, 

 

We have created the catalog item to automate the creation of Record Producer.

We have attached flow designer in the above catalog item so as the request is raised the record producer can be updated, created or retired.

 

For creating and updating the record producer we have created an action.

But in the action the target table is "sc_cat_item_producer" but the record didn't insert in the record producer table. Although the output generated has correct values and data. Record is not inserted in the target table. 

Pasting the action script.

 

(function execute(inputs, outputs) {

    var changes = [],
        variables = inputs.ritm.variables,
        operations = [];
    if (inputs.changes) {
        changes = JSON.parse(inputs.changes)
    }

    if (variables.type == "retire") {
        throw "Function does not retire catalog item.";
    }

 
    //CATALOG ITEM
    var previousItem;
    var currentItem = new GlideRecord("sc_cat_item_producer");
    if (variables.type == "update") {
        if (!currentItem.get(variables.record_producer)) {
            throw "Could not get existing catalog item";
        }
        previousItem = new GlideRecord("sc_cat_item_producer");
        if (!previousItem.get(variables.record_producer)) {
            throw "Could not get existing catalog item";
        }

    } else {
        //creating new record
        currentItem.initialize();
        currentItem.setNewGuidValue(gs.generateGUID());
        GlideTemplate.get(gs.getProperty("Template containing record producer fields")).apply(currentItem);
    }

    if (possible("record_name")) {
        currentItem.setValue("name", variables.record_name);
    }
    if (possible("catalog")) {
        //Taking catalog from category.sc_catalog and using that. Replacing old category catalog with new.
        var catalogs = [];
        var newCatalog = variables.category.sc_catalog.toString();
        if (variables.type == "update") {
            catalogs = previousItem.getValue("sc_catalogs").split(",");
            catalogs.replace(previousItem.category.sc_catalog.toString(), newCatalog);
        }
        if (catalogs.indexOf(newCatalog) == -1) {
            catalogs.push(newCatalog);
        }
        currentItem.setValue("sc_catalogs", catalogs);
        currentItem.setValue("category", variables.category);
    }
    if (possible("short_description")) {
        currentItem.setValue("short_description", variables.short_description);
    }
    if (possible("description")) {
        currentItem.setValue("description", variables.description);
    }
    if (possible("meta")) {
        currentItem.setValue("meta", variables.meta);
    }

})(inputs, outputs);
 
Please let me know if any comments.
2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Mansi Motwani1 

so did you check the sysId returned belongs to which table?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur, 

That sysid doesn't give any record. On Clicking it says no record found.

MansiMotwani1_0-1702458574934.png