Setting value to lookup field in freedom ui client side coding
Hi Community,
Setting value to lookup field using below syntax is not working. It seems this attribute ("PDS_UsrType_kkjfk5h
") does not have value and displayValue properties. Any idea please?
request.$context.PDS_UsrType_kkjfk5h = {
value: "someId",
displayValue: "Some Value"
};
By the way, i am calling the above inside request: "crt.HandleViewModelInitRequest".
Like
That is the correct way to set a lookup. There's an issue that was introduced in 8.0.8, I've not re-tested since 8.1.1, but the values set in the init (and resume) requests are overwritten by the page setting the default values. It's completely aggravating. Anyway, try wrapping the set in a setTimeout to see if causing a slight delay works (assuming your attribute name is correct):
setTimeout(() => { request.$context.PDS_UsrType_kkjfk5h = { value: "someId", displayValue: "Some Value" }; }, 300);
Ryan
Ryan Farley,
Hi Ryan,
Thank you so much, the work around is working.
Ryan Farley,
Hi Ryan,
I'm trying to clear the lookup, but setting its value like the following code shows doesn't seem to work. Do you have any ideas on how this could work?
setTimeout(() => { request.$context.attributes[addressAttributeName] = { "value": "00000000-0000-0000-0000-000000000000", "displayValue": "", "primaryImageValue": "", "primaryColorValue": "" }; }, 300);
There seem to be two problems with my code:
1.) the value for clearing the lookup is simply null
2.) the main problem was that I set the value directly to the attributes array, because the attribute name is stored in a variable and I didn't want to use eval(). Instead, we can use the setter function to do this:
request.$context.set(useContactAddress ? accountAddressAttributeName : contactAddressAttributeName, null);
Additional note: it seems setTimeout is not necessary any longer on
version 8.1.4
BR,
Robert
Robert Pordes,
Hello,
I'm doing in this way, and it's working,
request.$context.LookupAttribute_jy7bagb = { value: "00450aa2-269d-4ec1-ae6e-0eb0134ddfdb", displayValue: "Calificación" };