Fill the lookup value through JS


I want to fill the lookup value through JS. I am able to fill the value in a text field but lookup is not working. I am making sure that the value I am putting in the lookup field must be available in look list.

fd.spRendered(function() {
//if opened in dialog
if (window.frameElement && Dialog.getArgs()){
//set Description to the passed Description
fd.field("Title").value = Dialog.getArgs().Title;
fd.field('Response_x0020_To').value = Dialog.getArgs().Title;
fd.field('Department').value = "Accounting";

Response_x0020_To and Department are my lookup fields.

Hello @Ramiz,

You can set lookup field value only with the ID, not the title of the item.

fd.field('Lookup').value = 5;

Please find more information on managing lookup field with JavaScript here.

Thank you so much. It worked. :+1:

Can you tell me is it possible to open a new form set on click of button using Dialog?

Dear @Ramiz,
For opening any forms in dialog, please, check out the following section in JS documentation -

But for it to open a new form set, it must fulfill your routing conditions.

For example, this will work for forms opened in dialog:

if (window.frameElement){
    //redirect to this form set
    return '8720f859-7cca-4c51-8548-7a28f271d6a8';

@Nikita_Kurguzov Thank you for the response. I will try that.