Template field not getting updated

Posted by IramK on 18-Nov-2014 10:30

Hello,

I have a picklist and I would like to update a template field with the value of the currently selected picklist item so that the user cannot edit the value. How can I achieve this?

Posted by Orchid Corpin on 20-Nov-2014 11:02

I get it, sorry I thought it is a picklist with default values when you created them.

You may not need Template on this, you need textbox field and make this textbox readonly. See code below, change textBox in code.

$("#textBox").attr("readonly", true);

In the script component change the rbf_setFieldContent to rbf_setFieldValue.

Regards,

Orchid

All Replies

Posted by Orchid Corpin on 18-Nov-2014 11:41

In the object definition, edit the the template field and specify in the Template formula the token of your picklist.

Regards,

Orchid

Posted by IramK on 19-Nov-2014 03:12

I did.. but it doesn't update the value of the template field with the value that I get from my picklist. Any suggestions why?

Is it because its a non-editable field? I have been trying out different ways but I still can't get it to display the text on a template field.

Posted by Orchid Corpin on 19-Nov-2014 09:38

Are you in a New page? Values will take effect after save only.

Values are viewable in View and Edit page which values are already saved.

Regards,

Orchid

Posted by IramK on 20-Nov-2014 03:21

Yes, I am in a New page. So technically template fields would not dynamically update the values on a picklist selection? Is there any alternative to this? If I need to save the value of a currently selected picklist item? The picklist is dynamically generated so it doesn't currently save the value on clicking the "Save" button which is why I am trying to get the value and save it onto a template field.

Posted by Orchid Corpin on 20-Nov-2014 07:41

I see, to make this work before saving you do this:

1. Go to object definition, click on "Event" of the picklist

2. Specify a function in the "Onchange" event like the code below. Change the picklistID.

getPickValue($('#picklistID option:selected').text());

3.Save and go to New page

4. In New page specify the code below in your script component. Change templateName.

<script>
function getPickValue(val) {
	rbf_setFieldContent("templateName", val);
}
</script>

5. Save and Test.

Regards,

Orchid

Posted by IramK on 20-Nov-2014 08:59

Hello Orchid,

Thanks for your reply. It does update the template field now, but when I click on the save button.. it doesn't save the template field value. Do I need to do anything else?

Posted by Orchid Corpin on 20-Nov-2014 09:03

Hi,

I don't seem to find your comment here but I received it in my email.

"Reply by IramK

So would the picklist ID for an object called "Test" (integration name: test) would be "{!test#id}" ?"

ANSWER: use the integration name: test as well as the template field use also integration name.

Regards,

Orchid

Posted by Orchid Corpin on 20-Nov-2014 09:12

In the template field, do my first suggestion that specify {!yourPicklist#value} in the formula, my second suggestion is for viewing in the UI which you are in the New page.

Note: Template value depend on its formula inside. If it is empty then there will no template value.

Question: Does your picklist after save has a value?

Regards,

Orchid

Posted by IramK on 20-Nov-2014 09:13

Yeah I figured it out, hence deleted my reply. The updating part works but on save it still doesn't show the new value (because the picklist is dynamic).

Posted by Orchid Corpin on 20-Nov-2014 09:23

Make sure you still have the {!yourPicklist#value} in the template formula. See my comment above for details.

Regards,

Orchid

Posted by IramK on 20-Nov-2014 09:46

No my picklist doesn't save the value after save and that is because it is being populated dynamically i.e. I am doing a .empty() on the picklist and then populating it with the values I want which is why I would like the value to be saved on the template field. My template field still have the template formula : (!picklistname#value}. So thats all ok for now but the value is not saved.

Posted by Orchid Corpin on 20-Nov-2014 11:02

I get it, sorry I thought it is a picklist with default values when you created them.

You may not need Template on this, you need textbox field and make this textbox readonly. See code below, change textBox in code.

$("#textBox").attr("readonly", true);

In the script component change the rbf_setFieldContent to rbf_setFieldValue.

Regards,

Orchid

Posted by IramK on 20-Nov-2014 11:21

Ok finally that works. I am currently updating the textbox value but I was making the textbox read-only via rollbase rather than programmatically. Doing it programmatically did the job and saves the value. So now when I go back to "Edit"ing the form, the textbox is no longer read-only. Should the make it read-only onload? Would it still update the textbox value with the picklist value?

Just checked.. It does.. Marking this as answer. Thanks.

Posted by Orchid Corpin on 20-Nov-2014 11:25
Yes, making a textbox readonly via rollbase does not save a value, so we use jQuery on it.
Do the same code (in the script component) to the Edit page.

Regards,
Orchid
This thread is closed