Would like to include Regex Pattern in my existing client script.

KS13
Tera Contributor

Hello, 

I have an existing onSubmit catalog client script that displays and mandates a variable on the Task.

This variable needs to be restricted to allow the KBXXXXXXX format. 

I would like to include the following script into my onSubmit Catalog client script:

var pattern = /^[Kk][Bb]\d{7}$/;
    if (!pattern.test(newValue)) {
        alert('Please enter a valid KB article format. For example: KB0012345');
        g_form.setValue('kb_article', '');
        return;
    }
}
 -------------------------------------------------------------------------------------------------------------------
function onSubmit() {
    //Type appropriate comment here, and begin script below

    if (g_form.getValue('state') == '3' && g_form.getValue('short_description').indexOf('XYZ') > -1) {
        if (g_form.getValue('kb_article') == '') {
        g_form.setMandatory("kb_article", true);
        alert("Please enter mandatory information.");
    g_form.showFieldMsg('kb_article', 'Please enter mandatory information.');
        g_form.setValue('state', '1');
        return false;
    }
}
}
 
 Any help is always appreciated. 
2 ACCEPTED SOLUTIONS

James Chun
Kilo Patron

Hi,

 

Can you please elaborate on the issue you are experiencing?

Also, is it possible to use a reference type variable instead of a text type?

If so, you don't even need to have a client script to verify the input.

 

Thanks

View solution in original post

Robbie
Kilo Patron
Kilo Patron

Hi @KS13,

 

I'm struggling to understand why you’re allowing a user to free type into this field and then check if it’s a valid Knowledge Article via a regex.

Unless I’m missing something here, I’d recommend making this variable a field type of ‘Reference’ pointing at the Knowledge table.

This will ensure only valid Knowledge records can be selected whilst also providing you the ability (if required) to restrict the articles displayed by data points applicable to the articles such as active articles only, or from certain Knowledge bases, or restricted by knowledge categories for example.

 

Please note. A field of type Reference caters for a singe selection only which is based on my assumption based on your script above.

If you would like a user to be able to select more than one Knowledge article, select a field type of List Collector / GlideList. 

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

View solution in original post

2 REPLIES 2

James Chun
Kilo Patron

Hi,

 

Can you please elaborate on the issue you are experiencing?

Also, is it possible to use a reference type variable instead of a text type?

If so, you don't even need to have a client script to verify the input.

 

Thanks

Robbie
Kilo Patron
Kilo Patron

Hi @KS13,

 

I'm struggling to understand why you’re allowing a user to free type into this field and then check if it’s a valid Knowledge Article via a regex.

Unless I’m missing something here, I’d recommend making this variable a field type of ‘Reference’ pointing at the Knowledge table.

This will ensure only valid Knowledge records can be selected whilst also providing you the ability (if required) to restrict the articles displayed by data points applicable to the articles such as active articles only, or from certain Knowledge bases, or restricted by knowledge categories for example.

 

Please note. A field of type Reference caters for a singe selection only which is based on my assumption based on your script above.

If you would like a user to be able to select more than one Knowledge article, select a field type of List Collector / GlideList. 

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie