Skip to main content

Search

Set field value through Javascript

Comments

7 comments

  • Matthias_Walter

    Hi Kemal Sinanagic,

    can you please answer two question for me to better understand your challenge?

    1. when should hit field (Company Name) be set? -> on form load, on form save or on other field change
    2. what exactly do you wanna set? Is it a lookup field or a choice field? where do you want to get the value from?

     

    Regards

    Matthias

    0
  • KemalS

    Hi Matthias,

     

    The field should be set on form load.

    It's a lookup field. I'm getting the value from the metadata of the parent folder the item is located in, which has the same lookupfield.

     

    Thanks in advance

    Kemal

    0
  • Matthias_Walter

    Hi Kemal Sinanagic,

    I found an easier way using one of our functions to get the lookup value set.

    Set the following initial value expression on the lookup field:

    [[@Web.GetFirstValueForQuery('Folderlist', '<Where><BeginsWith><FieldRef Name=ServerUrl /><Value Type=Text>[[@Page.GetQueryString("RootFolder")]]</Value></BeginsWith></Where>', 'lookup')]].get_lookupId()+";#"

    Simply replace the parameters in bold with your list and field name and make sure the expression type is set to Assignment.

     

    Cheers

    Matthias

    0
  • KemalS

    Hey Matthias

     

    I'm getting the following error:

    FolderList = Claims

    lookup = Company_x0020_Name

     

    Thanks in advance

    Kemal

    0
  • KemalS

    When I replace the "[[@Page.GetQueryString("RootFolder")]]" with my own value like "/sites/GY/Lists/Claims/FolderName" then it works. Maybe the parser is messing something up here?

     

    So this works below (but not a solution):

    =[[@Web.GetFirstValueForQuery('Claims', '<Where><BeginsWith><FieldRef Name=ServerUrl /><Value Type=Text>/sites/GY/Lists/Claims/Folder</Value></BeginsWith></Where>', 'Company_x0020_Name')]].get_lookupId()+";#"

     

    Thanks in advance

    Kemal

    0
  • KemalS

    This works now:

     

    [[@Web.GetFirstValueForQuery('Claims', '<Where><BeginsWith><FieldRef Name=ServerUrl /><Value Type=Text>'+[[@Page.GetQueryString("RootFolder")]]+'</Value></BeginsWith></Where>', 'Company_x0020_Name')]].get_lookupId()+";#"

     

    Thanks for the help Matthias.

     

    One more question: it's not possible to set a field value through javascript? Should I need it in the future.

    0
  • Matthias_Walter

    Good to hear, but strange that it was working for me..

     

    Regarding the question "how to set a field value trough javascript?"; it depends on how you get the value to be set.

    • If you can get it within the context objects of the expression builder using our field placeholders or functions, you can set them as initial or calculated value or with a "Set field value" action.
    • If you need to get them asynchronous, you need to write them to the html controls manually in the onsuccess method and this is different from field type to field type.

     

    BR Matthias

    0

Please sign in to leave a comment.