Record Producer Variable

stevenm
Kilo Guru

I'm trying to change the field label or question value dynamically on a Record Producer.   This is an unmapped variable field whose label would change depending upon a value in another field.

For instance if I enter New in a dropdown I want another field label to say New Capacity:   If I enter Add in the same dropdown I want the field label to say Add Capacity.   I'll keep googling.

Thanks

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Steve,



For simplicity and maintenance, I would approach these as two different fields and expose them with a UI policy (or two) rather than messing with the complexity of changing a field label. No code involved and the people who come behind you in the years to come will be happier.


View solution in original post

7 REPLIES 7

This approach would be better indeed.



Thanks Chuck


So I would agree except for the ability to map a variable to a field, thus reducing the need to code in the record producer script.



As an example, let's say I have a multiple choice variable for a CI type, something like server, computer, printer, etc. Based on that selection, I set the reference qualifier for a variable that maps to the cmdb_ci field, setting the query to sys_class_name=current.variables.cmdb_ci.



If using a UI Policy or Client Script, I might want to change the label of the variable to instruct the user to select the appropriate CI class as appropriate.



The API documentation explicitly calls out that the function isn't supported by the Service Catalog and since Record Producers are exposed under the Catalog, it would make sense that it doesn't work.



Dennis


Hi Dennis,



Your user case makes sense however I would probably just keep the variables label generic (e.g. "Please select the appropriate item") instead of specifically calling out the CI Class to avoid maintenance overheads in the future.



Saying that however, I think it would be useful to know how to achieve this by a technical solution if dynamic labels are a necessity.



Have you tried DOM manipulation at all in your client script?


e.g.



var field = 'field_name'; // field_name is the database name for the variable


    var labelElement = $('label_' + g_form.getControl(field).id).select('label')[0];


    labelElement.innerHTML = 'New Field Name'; // New Field Name is the label name that will be set.


Thanks