Make category, description,meta and picture mandatory on newly creating catalog items.

BalimeniP
Tera Contributor

Currently when a new catalog item is requested, the category,detailed description and meta,picture are optional. Going forward it should not be like that without affecting existing catalog items ,how can we proceed with system ui policy or onsubmit client scripts,or any business rule 

2 REPLIES 2

HasanM
Kilo Sage

Hi @BalimeniP 

I'd avoid making these fields mandatory at dictionary level, because that would affect existing catalog items (and any update or import of them). Instead:

  1. Business rule (the main control, server-side)
    Table: sc_cat_item, When: before, Insert: true (and Update: true if you also want to enforce it on activation, see the note below).
(function executeRule(current, previous) {
    var missing = [];
    if (current.category.nil()) missing.push('Category');
    if (current.description.nil()) missing.push('Description');
    if (current.meta.nil()) missing.push('Meta');
    if (current.picture.nil()) missing.push('Picture');
    if (missing.length) {
        gs.addErrorMessage('Please populate: ' + missing.join(', '));
        current.setAbortAction(true);
    }
})(current, previous);

Use the condition "current.isNewRecord()" (or simply only tick Insert), so existing items aren't affected. If you'd rather enforce it when an item goes live, use the condition "Active changes to true" instead.

  1. onLoad client script (for user experience)
    Table: sc_cat_item
function onLoad() {
    if (g_form.isNewRecord()) {
        g_form.setMandatory('category', true);
        g_form.setMandatory('description', true);
        g_form.setMandatory('meta', true);
        g_form.setMandatory('picture', true);
    }
}

If this helped, please mark it as the accepted solution so others with the same question can find it.
Hope this helps.

Ankur Bawiskar
Tera Patron

@BalimeniP 

so what did you configure and what's not working?

share screenshots