Making Variable Editor fields read‑only & hiding on sn_customerservice_task extended tables

ClaudioG4376288
Tera Contributor

Context – how the variables land on my Task record

  1. A Record Producer lets users open a Case (in a scoped sn_customerservice_case extended table).

  2. That RP collects data via the usual Question & Answer variables.

  3. A Flow then spins off a follow‑up Task in my custom scoped sn_customerservice_task extended table.

  4. In that flow I duplicate every Question & Answer record (question_answer table) that belonged to the Case and rewrite two fields on each clone:

    • table_name  →  set to my sn_customerservice_task extended table.

    • table_sys_id  →  set to the sys_id of the Task I just created

This gives the Task its own Variable Editor populated with the same variables the user filled on the Case .


What I’m trying to do

On that Task form (Next Experience), for each variable pertaining to the Variable editor formatter section called "Variables":

  • Make every variable read‑only when the Task opens

  • Hide and turn off the mandatory for any variable whose value is empty or literally “None”

The application of such rules must be restricted only to the "Variables" section, this is important because there are also other variables on the forms.

I have tried the following code as a client script on load , global scope view on the sn_customerservice_task extended table, but it's not working, I have unchecked the isolation checkbox: Any help ? Thanks

 

/**

* Tipo   : onLoad

* Scopo  :

 *   - rendere read-only le variabili nella sezione indicata

*   - nascondere quelle senza valore o con valore “None”

*/

 

function onLoad() {

 

               /* -----------------------------------------------------------------

               * 0. Configurazione – cambia il titolo qui sotto con il TUO        *

               * ----------------------------------------------------------------- */

               var TARGET_SECTION = 'Variables';   // ← titolo della sezione

 

               /* -----------------------------------------------------------------

               * 1. Ricavo il DOM element della sezione                            *

               * ----------------------------------------------------------------- */

               var sectionEl = findSectionByTitle(TARGET_SECTION);

               if (!sectionEl) {                         // sezione non trovata? esci

                              console.warn('Section "' + TARGET_SECTION + '" non trovata.');

                              return;

               }

 

               /* -----------------------------------------------------------------

               * 2. Prendo la lista di tutte le variabili caricate nel form        *

               * ----------------------------------------------------------------- */

               var varNames = [];

               if (g_form.nameMap) {

                              g_form.nameMap.forEach(function (nm) {

                                            varNames.push('variables.' + nm.prettyName);

                              });

               } else if (g_form.prefixHandlers &&

                          g_form.prefixHandlers.variables &&

                          g_form.prefixHandlers.variables.handlerObject) {

                              g_form.prefixHandlers.variables.handlerObject.nameMap.forEach(

                                            function (nm) {

                                                           varNames.push('variables.' + nm.prettyName);

                                            }

                              );

               }

 

               /* -----------------------------------------------------------------

               * 3. Ciclo sulle variabili e filtro per sezione                     *

               * ----------------------------------------------------------------- */

               varNames.forEach(function (vName) {

 

                              var control = g_form.getControl(vName);      // DOM <input|select…>

                              if (!control || !sectionEl.contains(control)) {

                                            return;                                  // NON è nella sezione

                              }

 

                              /* 3.a   Read-only ------------------------------------------------*/

                              g_form.setReadOnly(vName, true);             // oppure usa

                              // g_form.setVariablesReadOnly(true);        // se vuoi l’intera VE

 

                              /* 3.b   Nascondi se vuota / “None” -------------------------------*/

                              var vVal = g_form.getValue(vName);

                              if (vVal === '' || vVal === 'None') {

                                            g_form.setMandatory(vName, false);

                                            g_form.setDisplay(vName, false);

                              }

               });

 

               /* -----------------------------------------------------------------

               * 4. Funzione di utilità: trovo la sezione per titolo               *

               * ----------------------------------------------------------------- */

               function findSectionByTitle(title) {

                              /*  In UI16 il titolo di sezione è uno <span class="label"> 

                                  dentro .section_header; da lì risalgo al contenitore.

                                  Se cambi tema/UI (ex: UI15) potresti dover adattare il selettore.

                              */

                              var headers = document.querySelectorAll('div.section_header span.label');

                              for (var i = 0; i < headers.length; i++) {

                                            if (headers[i].textContent.trim() === title) {

                                                           return headers[i].closest('div.sn-form-section, div.section');

                                            }

                              }

                              return null;

               }

}

 

ClaudioG4376288_0-1747219095549.png

 

0 REPLIES 0