Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: PFUN-16763

...

Create a Calculation Flow Logic with the following code: 

Code Block
if (api.isSyntaxCheckisInputGenerationExecution()) return


def quotesSaved = true
int i = 0
int step = 200
def qs = []
def quotes = []
def table = api.findLookupTable("QuotesEmailSent")
def tableValues = api.findLookupTableValues("QuotesEmailSent")
def quoteList = []
//create a list of quotes in the PP tracking table
for (quote in tableValues) {
  quoteList.add(quote.name)
}

//find all users in the approver group

def ug = api.find("U", Filter.equal("groups.uniqueName", "Marketing Manager"))

//create the list of e-mails of the users in the approver group

def emailList = []

for (e in ug) {
  emailList.add(e.email)
}

//iterate over saved quotes

while (quotesSaved) {
  qs = api.find("Q", i, step, null)
  
  if (qs.size() != 0) {
    quotes.addAll(qs)
    i += step
  } else {
    quotesSaved = false
  }

/*Find the quotes with the “Submit To” flag switched to “Yes” that are not in the tracking table, 
and generate the e-mails adding the quote(s) to the tracking tables. 
Find the quotes with the “Submit To” flag switched to “No” and remove the quote(s) from the tracking table*/

  for (q in qs) {
    def clic = api.getCalculableLineItemCollection(q?.typedId)
    for (lineItem in clic?.lineItems) {
      		if (lineItem.folder) continue
    }
	for (input in clic?.inputs) {

  		if (input.name == "submitForApproval" && input.value == "Yes" && !quoteList.contains(q.typedId)) {
          for (email in emailList) {
            api.sendEmail(email, "Submitted For Quote", "https://www.pricefx.eu/priceFxWeb.html?locale=en_US&targetPageState=" + q.typedId + "&targetPage=priceShopPage#priceShopPage")
          }	
          
          	updateRecord = [lookupTableId : table.id, "name" : q.typedId, "attribute1" : q.uniqueName, "attribute2" : q.lastUpdateDate]
          	api.addOrUpdate("MLTV", updateRecord)
        
        } else if (input.name == "submitForApproval" && input.value == "No") {
          existingRecord = [lookupTableId : table.id, "name" : q.typedId, "attribute1" : q.uniqueName, "attribute2" : q.lastUpdateDate]
          api.delete("MLTV", existingRecord)
        	}
  		}
	}
}

...

The full code (including HTML formatting for the e-mail) is avaliable available in Git - Copy_of_GenerateEmailOnQuoteSave_VA1.groovy