You are viewing limited content. For full access, please sign in.

Question

Question

Workflow SDK script issue

asked on November 21, 2017

Hello,

I have a workflow which includes a SDK script. The script searches through a specific folder and identifies all the document types within that folder, this result is then put into a string.

The script then compares the above string against a list of required documents, if all required documents are within the folder a token gets set to true, if false an email is sent to the user notifying them that documents are missing.

I want the script to identify which required documents are missing within the specific folder, which will then be stated within the email - I've had a quick play with tokens and some script that essentially said "does not contain" but no luck.

Example:  The specific folder has documents for: Eggs, Beans, Toast and Pancakes.

Required documents = Eggs, Beans, Toast, Pancakes and Sausages.

I would like the script to identify that Sausages is missing and then state this within the email body.

Any help would be greatly appreciated.

Thanks,

Andy

 

 

 

 

 

 

 

0 0

Answer

SELECTED ANSWER
replied on December 21, 2017

Hi Andrew,

 

Would you mind sharing the script? I think what you'll want to do is have two lists of strings in your script: one containing the required documents and one containing the documents found in whatever folder you're testing. You can then use some LINQ extension methods to generate the list of missing documents.

Here's a little snippet to show you what I mean:

using System;
using System.Linq;
using System.Collections.Generic;
					
public class Program
{
	public static void Main()
	{
		var requiredList = new List<string>
		{
			"Eggs",
			"Beans",
			"Toast",
			"Pancakes", 
			"Sausages"
		};
		
		var actualList = new List<string>
		{
			"Eggs",
			"Beans",
			"Toast",
			"Pancakes"
		};
		
		// Get list of names that are missing from source
		List<string> missingList = requiredList
				.Where(x => !actualList.Contains(x))
				.ToList();
		
		// Print missing names
		missingList.ForEach(x => Console.WriteLine(x));
	}
}
0 0

Replies

replied on November 22, 2017

Seems to me that your best bet is to create an empty Missing File(s) token near the top of the workflow.  Then after your Present File(s) token is filled, add a conditional sequence for each required file that runs if Present File(s) does not contain (or if that does not work, use does not match regular expression).  In each conditional sequence, update the Missing File(s) token.

0 0
replied on January 19, 2018 Show version history

Sorry for the late response on this question, I'll have a look at this today. Please find the current script below:


           

String documentType = GetTokenValue("RetrieveContractNumber_Contract Document Type").ToString();
            // Document type to be added
            if ((documentType.Equals("Daily Worksheet"))
            || (documentType.Equals("Site Diary - Supervisor"))
            || (documentType.Equals("Daily Diary"))
            || (documentType.Equals("Agreed Measures - Pre Invoice"))
            || (documentType.Equals("Invoice"))
            || (documentType.Equals("Contract Review"))) {

                // Get contract number from template
                String contractNumber = GetTokenValue("RetrieveContractNumber_Contract Number").ToString();

                // Start the search to retrieve other documents under this contract
                LFSearch contractDocumentSearch = this.Connection.Database.CreateSearch();
                contractDocumentSearch.Command = "{[Contracts]:[Contract Number]=\"" + contractNumber + "\"}";
                contractDocumentSearch.BeginSearch(true);

                // Grab the search results as a collection
                ILFCollection contractDocuments = contractDocumentSearch.GetSearchHits();
                LFSearchHit hit;
                ILFEntry entry;
                LFDocument doc;
                LFFieldData fields;
                List<String> documentTypes = new List<String>();

                // Cycle through each search result and grab the document type
                for (int i = 1; i <= contractDocuments.Count; i++) {
                    hit = (LFSearchHit)contractDocuments[i];
                    entry = (ILFEntry)hit.Entry;
                    if (entry.EntryType.Equals(Entry_Type.ENTRY_TYPE_DOCUMENT)) {
                        doc = (LFDocument)this.Connection.Database.GetEntryByID(entry.ID);
                        fields = (LFFieldData)doc.FieldData;

                        // Add document type to string array
                        documentTypes.Add(fields.get_FieldAsString("Contract Document Type"));
                        SetTokenValue("Require",documentTypes);
                    }
                }

                // Test output the contents of the document type array
                //for (int j = 0; j < documentTypes.Count; j++){
                //    MsgBox(documentTypes[j]);
                //}
                // Pre requisite document types
                if ((documentTypes.Contains("Enquiry Form or Tender"))
                && (documentTypes.Contains("Specification"))
                && (documentTypes.Contains("Quotation"))
                && (documentTypes.Contains("Client Order"))
                && (documentTypes.Contains("Risk Assessment"))
                && (documentTypes.Contains("Method Statement"))) {

                    SetTokenValue("RequiredDocuments", true);
                } else {

                    SetTokenValue("RequiredDocuments", false);
                }

}
                  }
        }
    }

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.