How to read the value from a Custom TextArea Variable in a record producer?

User664605
Kilo Guru

I have a Record Producer variable of type Custom. It uses a Widget to create a Texarea input tag .
I need to get the value entered into the TextBox and map it to a field on the target record in Record Producer main script. Here g_form.getValue doesn't help as its a custom variable.
Kindly share if it is achievable. If yes, then how?

Thanks in advance.

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@User664605 

see this working example, please enhance it further

I hope I answered your question

Widget HTML:

  <div>
  <label for="customTextArea">Enter your text:</label>
  <textarea id="customTextArea"
            class="form-control"
            ng-model="textValue"
            rows="5"
            placeholder="Type here..."></textarea>
</div>

Client controller:

api.controller = function($scope) {
    /* widget controller */
    var c = this;

    // Watch for changes and update the variable
    $scope.$watch('textValue', function(newVal, oldVal) {
        if (newVal !== oldVal) {
            // Update the catalog variable value
            var g_form = $scope.page.g_form || window.g_form;
            if (g_form && g_form.setValue) {
                g_form.setValue('application_type', newVal);
            }
        }
    });
};

Output: it adds value to the string variable, you just hide it

save custom type widget text area to catalog item variable.gif

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

@User664605 

it works fine, see below.

I used catalog UI policy to hide that variable and also using setValue() from widget to set the variable

Then once RITM is generated the value is still present in that single line text variable

widget variable setting.gif

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@User664605 

that's not going to work

You will have to do this

1) create a string type variable and hide it in your catalog item

2) then in that widget text area use client controller to observer the change and set the value entered into that text area into the hidden variable and then you can access it

Pass values from a Widget to a Catalog item variable 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@User664605 

see this working example, please enhance it further

I hope I answered your question

Widget HTML:

  <div>
  <label for="customTextArea">Enter your text:</label>
  <textarea id="customTextArea"
            class="form-control"
            ng-model="textValue"
            rows="5"
            placeholder="Type here..."></textarea>
</div>

Client controller:

api.controller = function($scope) {
    /* widget controller */
    var c = this;

    // Watch for changes and update the variable
    $scope.$watch('textValue', function(newVal, oldVal) {
        if (newVal !== oldVal) {
            // Update the catalog variable value
            var g_form = $scope.page.g_form || window.g_form;
            if (g_form && g_form.setValue) {
                g_form.setValue('application_type', newVal);
            }
        }
    });
};

Output: it adds value to the string variable, you just hide it

save custom type widget text area to catalog item variable.gif

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@User664605 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar 

Thanks much for a detailed response. 

But the issue here is the hidden field. Do you think g_form.setValue would work on a hidden field?
Kindly share your thoughts.

 

Regards,

Sameekshya