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

@User664605 

yes it should, that variable is on form but hidden so it should be able to set the value.

I believe I have answered your question with a working solution.

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 Thanks again for quick response
but i tried making it visible false via ui policy
And when i try setting it in the widget as shown by you; it doesnt get set

@User664605 

see my below response it worked fine for me

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 

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

@Ankur Bawiskar 
Here with the same setup; I dont see the values getting into the question_answer table as I am using a Record Producer.
May I know if any difference here?