CRM field validation

We are trying to get some CRM field validation working on a pair of fields on Sage1000 v6.1r.

The two fields are:

fstk_inprice_list – a checkbox, so Boolean field.

fstk_product_type – a multiselect with the following values:

Live – live

Non-Sales Item – nonsales

Non-Stock Item – nonstk

Obsolete Product – obs

Obsolete when Nill Stock – obsnill

No Product Image – noimg

We are trying to get CRM to prevent a single item, that has fstk_inprice_list AND fstk_product_type with a value of Obsolete Product – obs being selected at the same time, and Sage letting the record be saved. We would like this to be prevented. We have got the code for the checkbox working on its own, but cannot work out how to make the multiselect work properly – it works partially, but if you have multiple items selected in the multi-select it starts to break.

We do appreciate that it may be necessary to amend the short codes for our entries as there is crossover in them.

Below is the code we have been trying, in various forms:

var stringA = (Values('fstk_product_type'));

if (stringA.indexOf(",obs,")> -1)

{

Valid=false;

ErrorStr="Cannot be Obsolete and In Price List";

}

else

{

Valid=true;

}

var stringB = /(obsnull|obs)/g;

var stringC = /,obs,/;

var stringA = (Values('fstk_product_type'));

if ((stringB.test(stringA)) && (Values('fstk_inpricelist'))= true)

{

Valid=false;

ErrorStr="Cannot be Obsolete and In Price List";

}

else

{

Valid=true;

}

Can anyone see what’s going wrong here please?

Thanks

  • 0

    Taken a look at this, and I think it is the way it is looking at the array of the data in the muti select.

    I created a multi select that is the same as yours, I then added the following to the create, so it writes the value of the field to the error string:

    var Leh = Values("comp_dcl_multiselect");

    errorstr=Leh;

    When it first loads, I get:

    After I save, it shows:

    So my validate code of:


    if(Values("comp_dcl_multiselect").indexOf('obs') >= 0)

    {
    valid=false;
    errorstr = 'You cannot have Opt Out selected and Obsolete from the menu, change it';
    }
    else
    {
    valid=true;
    }


    Is being ignored. This seems to be the case, if I change what is selected in the multi select, so 'obs' appears first in the array, it validates and stops the save:

    Found this, from Jeff which explains it:

    https://community.sagecrm.com/partner_community/b/hints_tips_and_tricks/archive/2010/01/15/handling-the-data-in-multi-select-fields-in-validate-rules-and-table-level-scripts.aspx

    The code needs to be:


    var Che = FormValues("comp_dcl_multiselect");

    if(Che.indexOf('obs') >= 0)

    {
    valid=false;
    errorstr = 'You cannot have Opt Out selected and Obsolete from the menu, change it';
    }
    else
    {
    valid=true;
    }


    Getting the value of the multi select using FormValues as opposed to Values.

    Seems to then work as expected.