Skip to main content

Search

Using QueryList in Skybow Forms

Comments

6 comments

  • Christof Nussbaumer

    Hi Paul Shadwell

     

    With the QueryList methode you're on right track. I configured an ActionLink that sends an email with links to all documents from a Dossier (Dossierfolder "Dossier-ID") on click:

     

    This is the function code for email body:

    var documentLinks = '';
    var documents = [[@Site.QueryList('/sites/dev_cnu/bidirection-itemupdate/DossierDocuments', '<Where><Eq><FieldRef Name=\'FileDirRef\'/><Value Type=\'Lookup\'>/sites/dev_cnu/bidirection-itemupdate/DossierDocuments/Dossier-'+[[ID]]+'</Value></Eq></Where>', 100, '', 'Scope=\'Recursive\'') ]];
    var documentCount = documents.length;
    for (var i = 0; i < documentCount; i++) {
      documentLinks += "<a href=\""+[[@Web.Url]]+"/DossierDocuments/Dossier-"+[[ID]]+"/"+ documents[i].FileLeafRef +"\">"+ documents[i].FileLeafRef +"</a><br>";
    }
    return documentLinks;

     

    This is the result sent by email:

     

    Just adapt the Urls to your environment and modify the Caml Query (second parameter of QueryList) to your filter requirements.

     

    Hope this helps! Please let us know

    0
  • Paul J Shadwell

    Hi Christof,

    This is very useful thankyou.

    However, I'm not sure if this works for me:

    The CAML query should list all documents in a single document library (KeyDocs) with a column (TargetDate) that matches the date (also TargetDate) of the parent form.
    I am using this in Rich Forms installed as an Add-in with on-premise SharePoint 2016.

    The Action will be in a button on the parent form.

    Can you clarify the syntax a little more please?

    0
  • Christof Nussbaumer

    Hi Paul Shadwell

     

    Have a look at this function code:

    var msg = "The Following documents are ready for your approval:<br>"; 
    var documents = [[@Site.QueryList("/sites/dev_cnu/DossierDocuments", "<Where><Eq><FieldRef Name=\"TargetDate\"></FieldRef><Value  Type=\"DateTime\" IncludeTimeValue=\"FALSE\">"+[[=([[Start_x0020_Time]].getFullYear()+"-"+([[Start_x0020_Time]].getMonth()+1)+"-"+([[Start_x0020_Time]].getDate())+'T00:00:01Z')]]+"</Value></Eq></Where>", 100, "", "Scope=\"Recursive\"")]];
    var documentsLinks = documents.map(function(document){return document.FileRef;});
    documentsLinks = documentsLinks.join("<br>");
    return msg + documentsLinks;

     

    This code returns a string of all document (urls) that matches the "Start Time" date of the parent item.

    For sure you have to adapt the url of the document library and fields to your solution.

     

    If you need real links in email, just use add code parts from my previous comment.

    0
  • Paul J Shadwell

    Hi Christof, thanks again.

     

    I immediately tried your suggestion but got the following error when clicking the Send Email button:

    Failed evaluate property "Body" in "Send Email":Error occured on evaluating expression "{ var msg = "The Following documents are ready for your approval:<br>"; var documents = [[@Site.QueryList("/sites/Management/Key Documents", "<Where><Eq><FieldRef Name=\"TargetDate\"></FieldRef><Value Type=\"DateTime\" IncludeTimeValue=\"FALSE\">"+[[=([[Start_x0020_Time]].getFullYear()+"-"+([[Start_x0020_Time]].getMonth()+1)+"-"+([[Start_x0020_Time]].getDate())+'T00:00:01Z')]]+"</Value></Eq></Where>", 100, "", "Scope=\"Recursive\"")]]; var documentsLinks = documents.map(function(document){return document.FileRef;}); documentsLinks = documentsLinks.join("<br>"); return msg + documentsLinks; }"
    SyntaxError: Unexpected token %

     

    I don't see where Body is referenced in the code and the syntax looks ok yet I still get an error.

     

    What am I missing?

    0
  • Christof Nussbaumer

    Hi Paul Shadwell

     

    Your message says clearly the syntax error is in the emails body expression.

     

    I just configured same functionality button on my thenant. This is the result (email on the right is sent by clicking the button):

     

    And this is exactly the configuration:

    var msg = "The Following documents are ready for your approval:<br>"; 
    var documents = [[@Site.QueryList("/sites/dev_cnu/add-in-test-site/Shared Documents", "<Where><Eq><FieldRef Name=\"TargetDate\"></FieldRef><Value  Type=\"DateTime\" IncludeTimeValue=\"FALSE\">"+[[=([[Start_x0020_Time]].getFullYear()+"-"+([[Start_x0020_Time]].getMonth()+1)+"-"+([[Start_x0020_Time]].getDate())+'T00:00:01Z')]]+"</Value></Eq></Where>", 100, "", "Scope=\"Recursive\"")]];
    var documentsLinks = documents.map(function(document){return document.FileRef;});
    documentsLinks = documentsLinks.join("<br>");
    return msg + documentsLinks;

     

    The two dates fields are configured like:

    Field "Start Time" is in Date and Time Format: Date & Time

    Field "TargetDate" is in Date and Time Format: Date Only

     

    What is the language in which you created your site?

    Is the date format same as in my screenshots?

    0
  • Paul J Shadwell

    Hi Christof,

    I totally believe it works for you and the screenshots prove that. So it must be something I'm doing wrong.

    The language is English and the dates are in European format so 21st of January 2018 is 21/01/2018.

    I see yours is in US time standard.
    In your code I see that you are changing the format of StartTime to YYYY-MM-DD.

    I have even tried to simplify the query with "<Where><IsNotNull><FieldRef Name=\'Meeting_x0020_Date\'></FieldRef></IsNotNull></Where>" which when tested in straight Javascript returns 2 records.
    But in Forms returns a syntax error.

    0

Please sign in to leave a comment.