- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2018 12:41 PM
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:
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?
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2018 01:03 PM
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','');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2018 01:03 PM
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','');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2018 03:20 PM
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().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2018 01:07 PM
Hey Thomas,
Might be helpful to you.
Please Refer:
allow only integer in a variable
Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2018 01:48 PM
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