Drug order book automation
AutomateDrugOrderBook
Create a PrivateOrderInfo form for a pipeline variable for an automation.
ensure form PrivateOrderInfo
ensure section: Details
ensure field Link kind: hyperlink
ensure field TotalAmount kind: number
ensure field OldOrderStatus kind: pickText
sourceVar: VarOrderStatus
ensure field Handle kind: handle
ensure field OrderId kind: text
ensure field NewOrderStatus kind: pickText
sourceVar: VarOrderStatus
Set up an AutomateDrugOrderBook automation for the DrugOrderBook spreadsheet.
ensure automation AutomateDrugOrderBook kind: spreadsheet
spreadsheet: DrugOrderBook
1. BeforeInsert
Add a BeforeInsert event to the AutomateDrugOrderBook automation.
// event, BeforeInsert
ensure event BeforeInsert fire: beforeInsert
a. CopyFieldRowId
Create a VarMappingDrugOrderToDrugOrder2 variable to map data between the source and target forms in the CopyFieldRowId automation step.
ensure var VarMappingDrugOrderToDrugOrder2 kind: mapping
deploy: fixedOnDeploy
fromForm: EntityDrugOrder
toForm: EntityDrugOrder
fieldMappingMap: {
'updateVariant': 'updateForced',
'emptyVariant': 'ignoreEmptyField',
'map': {
'${f:SysRowId}': 'Details.RowId'
}
}
Add a CopyFieldRowId step to the BeforeInsert event to copy the rowId.
// step, copyField, CopyFieldRowId
ensure automation AutomateDrugOrderBook
ensure event BeforeInsert
ensure step CopyFieldRowId kind: copyField
mappingVar: VarMappingDrugOrderToDrugOrder2
2. AfterInsert
Add an AfterInsert event to the AutomateDrugOrderBook automation and assign a PipelineOrderLink pipeline variable to the event.
// event, AfterInsert
ensure event AfterInsert fire: afterInsert
// pipelineVar, PipelineOrderLink
ensure pipelineVar PipelineOrderLink form: PrivateOrderInfo
a. CopyFieldCustomer
Create a VarMappingDrugOrderToDrugOrder variable to map data between the source and target forms in the CopyFieldCustomer automation step.
ensure var VarMappingDrugOrderToDrugOrder kind: mapping
deploy: fixedOnDeploy
fromForm: EntityDrugOrder
toForm: EntityDrugOrder
fieldMappingMap: {
'updateVariant': 'updateForced',
'emptyVariant': 'ignoreEmptyField',
'map': {
'${f:SysCreatedBy}': 'Details.Customer'
}
}
Add a CopyFieldCustomer step to the AfterInsert event to copy the customer.
// step, copyField, CopyFieldCustomer
ensure automation AutomateDrugOrderBook
ensure event AfterInsert
ensure step CopyFieldCustomer kind: copyField
mappingVar: VarMappingDrugOrderToDrugOrder
b. CopyFields
Create a VarMappingDrugOrderToPrivateForm variable to map data between the source and target forms in the CopyFields automation step.
ensure var VarMappingDrugOrderToPrivateForm kind: mapping
deploy: fixedOnDeploy
fromForm: EntityDrugOrder
toForm: PrivateOrderInfo
fieldMappingMap: {
'map': {
'${f:Summary.TotalBill}': 'Details.TotalAmount',
'${f:Details.Handle}': 'Details.Handle',
'${f:Details.OrderNo}': 'Details.OrderId',
'${f:Summary.OrderStatus}': 'Details.OldOrderStatus'
}
}
Add a CopyFieldCustomer step to the AfterInsert event to copy multiple fields from the source form to the target form.
// step, copyField, CopyFields
ensure automation AutomateDrugOrderBook
ensure event AfterInsert
ensure step CopyFields kind: copyField
targetPipelineVar: PipelineOrderLink
mappingVar: VarMappingDrugOrderToPrivateForm
c. DeeplinkDrugOrder
Add a GenerateDeeplinkDrugOrder step to the AfterInsert event to create the deeplink for the EntityOrder form using the provided order values.
// step, generateDeeplink, GenerateDeeplinkDrugOrder
ensure step GenerateDeeplinkDrugOrder kind: generateDeeplink
outputFormPipelineVar: PipelineOrderLink
deeplinkField: Details.Link
deeplink: DeeplinkDrugOrder
d. MsgSendOnWhatsapp
Create the message variables for the SendWhatsappTemplateMessage automation step, VarTextPatternMsg1, VarTextPatternMsg2, and VarTextPatternMsg3
ensure var VarTextPatternMsg1 kind: text
deploy: fixedOnDeploy
value: "Thank you for your repeat order!"
ensure var VarTextPatternMsg2 kind: text
deploy: fixedOnDeploy
value: "New order id: ${P1}, amount: ${P2}, status: ${P3}"
ensure var VarTextPatternMsg3 kind: text
deploy: fixedOnDeploy
value: "Access your order ${P}"
Add a SendWhatsappTemplateMessage step to the AfterInsert event to send a WhatsApp message upon order placement.
// step, messageSendOnWhatsapp, MessageSendOnWhatsapp
ensure automation AutomateDrugOrderBook
ensure event AfterInsert
ensure step SendWhatsappTemplateMessage kind: sendWhatsappTemplateMessage
inputFormPipelineVar: PipelineOrderLink
dataSourceField: Details.Handle
templateGroupId: "36ab8ba797dc5cba4ec7e0b040ee8591"
messageVarMap: [
"{'var':'VarTextPatternMsg1'}",
"{'var':'VarTextPatternMsg2',
'paramSet':[
'${f:Details.OrderId}',
'${f:Details.TotalAmount}',
'${f:Details.OldOrderStatus}'
]}",
"{'var':'VarTextPatternMsg3','paramSet':['${f:Details.Link}']}"
]
e. MessageSendOnEmail
Create a VarParagraphPatternBody variable for the SendEmail automation step.
ensure var VarParagraphPatternBody kind: paragraph
deploy: fixedOnDeploy
value: "<b>Thank you for your repeat order.</b>
New Order Id : ${P}
Order amount: ${P1}
Order status: ${P2}
Access your order ${P3}"
Add a SendEmail step to the AfterInsert event to send an email upon order placement.
// step, messageSendOnEmail, MessageSendOnEmail
ensure automation AutomateDrugOrderBook
ensure event AfterInsert
ensure step SendEmail kind: sendEmail
inputFormPipelineVar: PipelineOrderLink
dataSourceField: Details.Handle
messageVar: {
'var': 'VarParagraphPatternBody',
'paramSet': [
'${f:Details.OrderId}',
'${f:Details.TotalAmount}',
'${f:Details.OldOrderStatus}',
'${f:Details.Link}'
]
}
subjectVar: {
'var': 'VarTextPatternMsg1'
}
f. ForwardToGroups
Add a ForwardToGroups step to the AfterInsert event to forward the message to the specified groups.
// step, forwardToGroups, ForwardToGroups
ensure step ForwardToGroups kind: forwardToGroups
senderRole: $Self
groups: [DrugOrderBook]
3. BeforeUpdate
Add a BeforeUpdate event to the AutomateDrugOrderBook automation and assign a PipelineOrderStatus pipeline variable to the event.
// event, BeforeUpdate
ensure event BeforeUpdate fire: beforeUpdate
// pipelineVar, PipelineOrderStatus
ensure pipelineVar PipelineOrderStatus form: PrivateOrderInfo
a. GetSpreadsheetRows
Create a VarMappingDrugOrderToPrivateForm1 variable to map data between the source and target forms in the GetSpreadsheetRows automation step.
ensure var VarMappingDrugOrderToPrivateForm1 kind: mapping
deploy: fixedOnDeploy
fromForm: EntityDrugOrder
toForm: PrivateOrderInfo
fieldMappingMap: {
'map': {
'${f:Summary.OrderStatus}': 'Details.OldOrderStatus',
'${f:Details.Handle}': 'Details.Handle'
}
}
Create a VarConditionGetLastRow variable to filter the data for the GetSpreadsheetRows automation step.
ensure var VarConditionGetLastRow kind: condition deploy: fixedOnDeploy
value: "<root>
<stmt>${f:Details.RowId} == ${in:Details.RowId}</stmt>
</root>"
sourceForm: EntityDrugOrder
inputForm: EntityDrugOrder
Add a GetSpreadsheetRows step to the BeforeUpdate event to get the filtered spreadsheet rows.
// step, getSpreadsheetRows, GetSpreadsheetRows
ensure automation AutomateDrugOrderBook
ensure event BeforeUpdate
ensure step GetSpreadsheetRows kind: getSpreadsheetRows
targetSpreadsheet: DrugOrderBook
targetSpreadsheetFilterVar: VarConditionGetLastRow
outputFormPipelineVar: PipelineOrderStatus
targetToSourceMappingVar: VarMappingDrugOrderToPrivateForm1
b. CopyFieldStatus
Create a VarMappingDrugOrderToPrivateForm1 variable to map data between the source and target forms in the CopyFieldStatus automation step.
ensure var VarMappingDrugOrderToPipeline kind: mapping
deploy: fixedOnDeploy
fromForm: EntityDrugOrder
toForm: PrivateOrderInfo
fieldMappingMap: {
'map': {
'${f:Summary.OrderStatus}': 'Details.NewOrderStatus',
'${f:Details.OrderNo}': 'Details.OrderId'
}
}
Add a CopyFieldStatus step to the BeforeUpdate event to copy the old order status.
// step, copyField, CopyFieldStatus
ensure automation AutomateDrugOrderBook
ensure event BeforeUpdate
ensure step CopyFieldStatus kind: copyField
targetPipelineVar: PipelineOrderStatus
mappingVar: VarMappingDrugOrderToPipeline
4. AfterUpdate
Add an AfterUpdate event to the AutomateDrugOrderBook automation.
// event, AfterUpdate
ensure event AfterUpdate fire: afterUpdate
a. DeeplinkDrugOrder
Add a GenerateDeeplinkDrugOrder step to the AfterUpdate event to create the deeplink for the EntityOrder form using the provided order values.
// step, generateDeeplink, GenerateDeeplinkDrugOrder
ensure step GenerateDeeplinkDrugOrder kind: generateDeeplink
outputFormPipelineVar: PipelineOrderStatus
deeplinkField: Link
deeplink: DeeplinkDrugOrder
b. MessageSendOnEmail
Create a VarConditionIsOrderStatusChange variable to trigger either the SendEmail or SendWhatsappUpdateMessage automation step if there is a change in the order status.
ensure var VarConditionIsOrderStatusChange kind: condition
deploy: fixedOnDeploy
value: "<root>
<stmt>${f:Summary.OrderStatus} != ${in:Details.OldOrderStatus}</stmt>
</root>"
sourceForm: EntityDrugOrder
inputForm: PrivateOrderInfo
Create a VarConditionIsOrderStatusChange variable to serve as the email body text for the SendEmail automation step.
ensure var VarParagraphPatternBody1 kind: paragraph
deploy: fixedOnDeploy
value: "<b>We have update for you for</b>
Order id ${P}
Status changed to ${P1}.
Access your order ${P2}"
Create a VarTetPatternSubject variable to serve as the email subject text for the SendEmail automation step.
ensure var VarTetPatternSubject kind: text
deploy: fixedOnDeploy
value: "Your order"
Add a SendEmail step to the AfterUpdate event to send an email when the order status changes.
// step, messageSendOnEmail, MessageSendOnEmail
ensure automation AutomateDrugOrderBook
ensure event AfterUpdate
ensure step SendEmail kind: sendEmail
executionConditionVar: VarConditionIsOrderStatusChange
executionConditionInputPipelineVar: PipelineOrderStatus
inputFormPipelineVar: PipelineOrderStatus
dataSourceField: Details.Handle
subjectVar: {
'var': 'VarTetPatternSubject'
}
messageVar: {
'var': 'VarParagraphPatternBody1',
'paramSet': [
'${f:Details.OrderId}',
'${f:Details.TotalAmount}',
'${f:Details.Link}'
]
}
c. MsgSendOnWhatsapp
Create a VarTextPatternUpdateMsg variable to serve as the message body text for the SendWhatsappUpdateMessage automation step.
ensure var VarTextPatternUpdateMsg kind: text
deploy: fixedOnDeploy
value: "For order id ${P}, status changed to ${P1}"
Add a SendWhatsappUpdateMessage step to the AfterUpdate event to send the WhatsApp message when the order status changes.
// step, messageSendOnWhatsapp, MessageSendOnWhatsapp
ensure automation AutomateDrugOrderBook
ensure event AfterUpdate
ensure step SendWhatsappUpdateMessage kind: sendWhatsappTemplateMessage
templateGroupId: "eea7e4bfb365b7e6c77d3839a91ce279"
executionConditionVar: VarConditionIsOrderStatusChange
executionConditionInputPipelineVar: PipelineOrderStatus
inputFormPipelineVar: PipelineOrderStatus
dataSourceField: Details.Handle
messageVarMap: [
"{'var':'VarTextPatternUpdateMsg',
'paramSet':[
'${f:Details.OrderId}',
'${f:Details.NewOrderStatus}'
]}",
"{'var':'VarTextPatternMsg3','paramSet':['${f:Details.Link}']}"
]
AutomateRepeatDrugOrder
Set up an AutomateRepeatDrugOrderSheet automation for the RepeatDrugOrderSheet spreadsheet.
ensure automation AutomateRepeatDrugOrderSheet kind: spreadsheet
spreadsheet: RepeatDrugOrderSheet
1. BeforeInsert
Add a BeforeInsert event to the AutomateRepeatDrugOrderSheet automation.
// event, BeforeInsert
ensure event BeforeInsert fire: beforeInsert
a. CopyFieldCustomer
Create a VarMappingRepeatOrderToRepeatOrder variable to map data between the source and target forms in the CopyFieldCustomer automation step.
ensure var VarMappingRepeatOrderToRepeatOrder kind: mapping
deploy: fixedOnDeploy
fromForm: EntityRepeatDrugOrder
toForm: EntityRepeatDrugOrder
fieldMappingMap: {
'updateVariant': 'updateForced',
'emptyVariant': 'ignoreEmptyField',
'map': {
'${f:SysCreatedBy}': 'Details.Customer'
}
}
Add a CopyFieldCustomer step to the BeforeInsert event to copy the customer.
// step, copyField, CopyFieldCustomer
ensure automation AutomateRepeatDrugOrderSheet
ensure event BeforeInsert
ensure step CopyFieldCustomer kind: copyField
mappingVar: VarMappingRepeatOrderToRepeatOrder
2. AfterInsert
Add an AfterInsert event to the AutomateRepeatDrugOrderSheet automation and assign a PipelineRepeatOrder pipeline variable to the event.
// event, AfterInsert
ensure event AfterInsert fire: afterInsert
// pipelineVar, PipelineRepeatOrder
ensure pipelineVar PipelineRepeatOrder form: EntityDrugOrder
a. CallReport
i. ReportLastOrder
Create a ReportLastOrderCustomer report to retrieve the customer's information.
ensure report ReportLastOrderCustomer kind: query
inputForm: EntityRepeatDrugOrder
outputForm: EntityDrugOrder
fromSpreadsheets: [DrugOrderBook]
neoQL: "SELECT
${ss:DrugOrderBook.Details.CustomerName} as ${out:Details.CustomerName},
${ss:DrugOrderBook.Details.Address} as ${out:Details.Address},
${ss:DrugOrderBook.Details.Handle} as ${out:Details.Handle},
${ss:DrugOrderBook.Details.Customer} as ${out:Details.Customer},
${ss:DrugOrderBook.Summary.Orderlink} as ${out:Summary.Orderlink}
FROM ${ss}
WHERE ${ctx:row.type} = ${ss:DrugOrderBook}
AND ${ss:DrugOrderBook.Details.Customer.value} = ${in:Customer}
ORDER BY ${ctx:row.createdOn} DESC
LIMIT 1"
Create a ReportLastOrderGrid report to retrieve the customer's most recent order itmes.
ensure report ReportLastOrderGrid kind: query
inputForm: EntityRepeatDrugOrder
outputForm: EntityDrugOrder
fromSpreadsheets: [DrugOrderBook]
neoQL: "With q1 as
(
SELECT
${ctx:row.id} as `id`
FROM ${ss}
WHERE ${ctx:row.type} = ${ss:DrugOrderBook}
AND ${ss:DrugOrderBook.Details.Customer.value} = ${in:Customer}
ORDER BY ${ctx:row.createdOn} DESC
LIMIT 1
),
q2 as
(
SELECT
${ctx:row.parentId} as `pid`,
${ss:DrugOrderBook.Items.Quantity} as `qty`,
${ss:DrugOrderBook.Items.ItemMasterRowId} as `itemRowId`,
${ss:DrugOrderBook.Items.Name} as `drugName`,
${ss:DrugOrderBook.Items.Ingredient} as `ingredient`,
${ss:DrugOrderBook.Items.Brand} as `brand`,
${ss:DrugOrderBook.Items.Dose} as `dose`,
${ss:DrugOrderBook.Items.Pack} as `pack`,
${ss:DrugOrderBook.Items.DiscountedPrice} as `dsicountedPrice`,
${ss:DrugOrderBook.Items.MRP} as `mrp`
FROM ${ss}
WHERE ${ctx:row.type} = ${ss:DrugOrderBook.Items}
)
SELECT
q2.qty as ${out:Items.Quantity},
q2.itemRowId as ${out:Items.ItemMasterRowId},
q2.drugName as ${out:Items.Name},
q2.ingredient as ${out:Items.Ingredient},
q2.brand as ${out:Items.Brand},
q2.dose as ${out:Items.Dose},
q2.pack as ${out:Items.Pack},
q2.dsicountedPrice as ${out:Items.DiscountedPrice},
q2.mrp as ${out:Items.MRP}
FROM q1
JOIN q2 ON q1.id = q2.pid"
Create a ReportRepeatLastOrder report to retrieve the customer's most recent order.
ensure report ReportRepeatLastOrder kind: composite
inputForm: EntityRepeatDrugOrder
outputForm: EntityDrugOrder
mergeReports: [ReportLastOrderCustomer, ReportLastOrderGrid]
ii. Step
Create a VarMappingDrugOrderToDrugOrder1 variable to map data between the source and target forms in the CallReportRepeatLastOrder automation step.
ensure var VarMappingDrugOrderToDrugOrder1 kind: mapping
deploy: fixedOnDeploy
fromForm: EntityDrugOrder
toForm: EntityDrugOrder
fieldMappingMap: {
'map': {
'${f:Details.Date}': 'Details.Date',
'${f:Details.Customer}': 'Details.Customer',
'${f:Details.CustomerName}': 'Details.CustomerName',
'${f:Details.Address}': 'Details.Address',
'${f:Summary.OrderStatus}': 'Summary.OrderStatus',
'${f:Summary.TotalBill}': 'Summary.TotalBill',
'${f:Details.Handle}': 'Details.Handle'
}
}
gridMappingMap: {
'Mapping2Dhsl4': {
'fromGrid': 'Items',
'toGrid': 'Items',
'fromKey': '$RowId',
'toKey': '$RowId',
'insertVariant': 'insertForced',
'updateVariant': 'updateForced',
'removeVariant': 'removeForced',
'emptyVariant': 'overrideEmptyField',
'map': {
'${f:Items.Quantity}': 'Items.Quantity',
'${f:Items.ItemMasterRowId}': 'Items.ItemMasterRowId',
'${f:Items.Name}': 'Items.Name',
'${f:Items.Ingredient}': 'Items.Ingredient',
'${f:Items.Brand}': 'Items.Brand',
'${f:Items.Dose}': 'Items.Dose',
'${f:Items.Pack}': 'Items.Pack',
'${f:Items.DiscountedPrice}': 'Items.DiscountedPrice',
'${f:Items.MRP}': 'Items.MRP',
'${f:Items.Total}': 'Items.Total'
}
}
}
Add a CallReportRepeatLastOrder step to the AfterInsert event to trigger a report that retrieves the customer's most recent order.
// step, callReport, CallReportRepeatLastOrder
ensure automation AutomateRepeatDrugOrderSheet
ensure event AfterInsert
ensure step CallReportRepeatLastOrder kind: callReport
targetReport: ReportRepeatLastOrder
outputPipelineVar: PipelineRepeatOrder
reportOutputMappingVar: VarMappingDrugOrderToDrugOrder1
b. InsertIntoOrderSheet
Add an InsertIntoDrugOrderSheet step to the AfterInsert event to add the new order details to the DrugOrderBook spreadsheet.
// step, insertIntoSpreadsheet, InsertIntoDrugOrderSheet
ensure step InsertIntoDrugOrderSheet kind: insertIntoSpreadsheet
targetSpreadsheet: DrugOrderBook
inputFormPipelineVar: PipelineRepeatOrder
sourceToTargetMappingVar: VarMappingDrugOrderToDrugOrder1