Numeric field in record producer

thomaskennedy
Tera Guru

I have a requirement for the user to supply a numeric value in a record producer. The target table has an Integer column named quantity_affected.

So I tried what is suggested here:

1. Added a ui macro called numeric_input:

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<input type="number" step="1" min="1" name="quantity_affected" id="quantity_affected" max="1000"/>

</j:jelly>

2. Added a variable of type Macro With Label to my producer:

image1.png

image2.png

When I submit the producer, the resulting record has no value for quantity_affected. There's no error message anywhere.

I also tried mapping the variable to the quantity_affected field (not shown here).

I put in an onSubmit client script to peek at the producer variables using g_form.getValue(), and the other fields are reported correctly, but it does not see any value for quantity_affected. This makes a certain amount of sense, as the markup in the macro is clearly being wrapped up somehow, so g_form will not see it by that name, anyway.

So, how do you use this macro to implement a number control in a producer and make sure it gets mapped to a column in the target table?

1 ACCEPTED SOLUTION

ark6
Mega Guru

I wouldn't go with a macro either as macros sometimes don't work in Service Portal.



Instead I would create a single line text field and write an onchange client script as below.



function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }




    //Type appropriate comment here, and begin script below


    var pattern=/[^\d]/g;


var b=pattern.test(newValue);


if(b=='true')


{


g_form.hideFieldMsg('numeric'); //name of the field you are using


g_form.addErrorMessage('numeric',"Please Enter numerical value only","error");


g_form.setValue('numeric','');


}


}


View solution in original post

5 REPLIES 5

ark6
Mega Guru

I wouldn't go with a macro either as macros sometimes don't work in Service Portal.



Instead I would create a single line text field and write an onchange client script as below.



function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }




    //Type appropriate comment here, and begin script below


    var pattern=/[^\d]/g;


var b=pattern.test(newValue);


if(b=='true')


{


g_form.hideFieldMsg('numeric'); //name of the field you are using


g_form.addErrorMessage('numeric',"Please Enter numerical value only","error");


g_form.setValue('numeric','');


}


}


Thank you, that's the approach I will take, one onChange client script with a polite showFieldMsg() and an onSubmit with a hidefieldMsg() and a showErrorMsg().


Rajesh Mushke
Mega Sage
Mega Sage

Hey Thomas,



Might be helpful to you.



Please Refer:


Catalog Item - Numeric Value


allow only integer in a variable




Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

Inactive_Us1586
Kilo Contributor

Hi,



Check the Name of the field of variable in Record Producer. It should work.



Thanks.



PS: Your feedback (Like, Helpful or Correct) helps community