Page 1 of 2

Initial value in field

Posted: 13 Apr 2017
by alexey.babin
Hello!

I use formDesigner and I would like to set the initial value in field depending on user, who is working with form. I prepare the array

[ItemId, ItemName]

to pass it to method fd.field("FieldName").value(), and sometimes it works well, somtimes not. I understand, that this happens because lookup control rendering is asyncronous, and sometimes when I pass the array, the control is not ready.

So is there event on which I can subscribe to cath the moment when I could set the initial value?

Thanks!

Re: Initial value in field

Posted: 14 Apr 2017
by Dmitry Kozlov
Hi,
Please, pass the initial value to a Cross-site Lookup field in the following format and it will work even if the control is not loaded yet:
fd.field('Lookup').value('120;#Child');

Re: Initial value in field

Posted: 14 Apr 2017
by alexey.babin
Now works great. Thanks a lot!

Re: Initial value in field

Posted: 11 Jul 2017
by AlexStenAlexSten
Hi all,
is it possible to set the initial value using variables?
ie:
fd.field('Lookup').value('varParentID;varParentTile');
I don't know the correct syntax.

My scenario is: parent form (Discussions), with a lookup and a related document.
When adding a new document from the parent form, the child form opens.
The child form has a lookup pointing to the parent (Discussions), and I need to set it with the parentID and parentTitle, to link them together.

thank you

Re: Initial value in field

Posted: 11 Jul 2017
by Nikita Kurguzov
Hello, Alex!
If I understand correctly, you want to automatically bind newly uploaded documents added to the Related Items to the Parent form. Here you can read on how it's done - https://spform.com/documentation/related-documents This is only for documents, you can simply drag and drop them to the Related Items list.

If you want to create New Items (not documents) with Related Items and bind them to the Parent automatically, here we have an instruction on how to do it properly - https://spform.com/documentation/relate ... gular-mode This is only for items.

Please, follow every step in the instructions as all of them are very important.

Re: Initial value in field

Posted: 11 Jul 2017
by AlexStenAlexSten
hi Nikita,
thank you for your prompt support.

Re: Initial value in field

Posted: 12 Jul 2017
by AlexStenAlexSten
Hi Nikita,
I followed step by step your advice, but I’m still missing something and hope you can help.
This is my scenario:
I have a parent list “Discussion_parent” where I add documents with the Related Items.
When clicking on “New Document”, I select a document, then the Child Form “Documents_child” opens, but the lookup “Discussions” that is linked to the field “Subject” in the parent, is empty.
I could select from the “Discussions” dropdown the correct value, but I need that this is automatically set to the parent value, to make sure it’s alway correctly linked to it.
That’s why I was looking to set field “Discussions” on form load, retrieving parent form values (i.e. fd.field('Lookup').value('120;#Child'); ).
The lookup “Discussions” has ID and Subject columns.
Hope this have sense for you.

Re: Initial value in field

Posted: 12 Jul 2017
by Nikita Kurguzov
Hello, Alex!
Which of the two instructions are you referring to? Related Documents or Related Items Regular Mode?

As far as I understand, you have Discussions list, where you added Related Items field to the forms, you try to add new documents there and they are not being linked. Does it happen with both New Form and Edit Form or only with one of them? What about your Documents - is it a List or a Document Library?

Just add some screenshots of the forms, so we can take a closer look at them and determine what exactly needs fixing.

One last thing, if you experience troubles with the edit form, please replace:

Code: Select all

var parentId = window.top.GetUrlKeyValue('ID');
with

Code: Select all

var parentId = parseInt(window.top.GetUrlKeyValue('ID'));
We've updated the instruction, this line was causing a bug to appear in certain circumstances.

Re: Initial value in field

Posted: 12 Jul 2017
by AlexStenAlexSten
screenshot_01.png
screenshot_01.png (49.76 KiB) Viewed 3225 times
Nikita,
I have added a screenshot and I'm going to review all the code.

thank you

Re: Initial value in field

Posted: 12 Jul 2017
by Nikita Kurguzov
What about using Drag and Drop feature? If you set up everything according to this instruction, it should work -
https://spform.com/documentation/related-documents

Just change the code to your field name:

Code: Select all

fd.updateDroppedDocuments($('.related-docs'), {
  Discussioni: '{CurrentItem}'
});
You can also write additional code to fill in the rest of the fields. But you won't be able to click "New Document", instead you will just drop documents into the list.