So I am getting error when I try to get if statements on the result set that i get it from below query.
MEmail is variable i decleared in page and based on that i am running query against recipient to check if it exists. if record exists , then send one delivery else send another is plan.
var query = xtk.queryDef.create(
<queryDef schema="nms:recipient" operation="getIfExists">
<select>
<node expr="@email"/>
<node expr="@id"/>
</select>
<where>
<condition expr={"@email='"+ctx.vars.MEmail+"'"}/>
</where>
</queryDef>
)
var res = query.ExecuteQuery()
// Send email
if(res.@email!=''){
nms.delivery.QueueNotification('mediaconfirmationwid',
<delivery>
<targets>
<deliveryTarget>
<targetPart type='query' exclusion='false' ignoreDeleteStatus='false'>
<where>
<condition expr={'@id ='+ res.@id}/>
</where>
</targetPart>
</deliveryTarget>
</targets>
</delivery>)
}
if(res.@email=''){
nms.delivery.QueueNotification('mediaconfirmationwid',
<delivery>
<targets>
<deliveryTarget>
<targetPart type='query' exclusion='false' ignoreDeleteStatus='false'>
<where>
<condition expr={'@id ='+ res.@id}/>
</where>
</targetPart>
</deliveryTarget>
</targets>
</delivery>)
}
if I remove if statement i get delivery but the moment i add if and conditions i dont get delivery.
Solved! Go to Solution.
Views
Replies
Total Likes
//Defined getIfExists
var query = xtk.queryDef.create(
<queryDef schema="nms:recipient" operation="getIfExists">
<select>
<node expr="@email"/>
<node expr="@id"/>
</select>
<where>
<condition expr={"@email='"+ctx.recipient.@email+"'"}/>
<condition expr={"@sourceType='Media'"}/>
</where>
</queryDef>
)
var res = query.ExecuteQuery()
//Run the query
var res = query.ExecuteQuery()
//Called if statement worked
if(res.@email.length()>0){
nms.delivery.QueueNotification
Hi @Prasanna_Soni,
I tried executing the below js in the web app. I am able to receive the delivery for 1st if(res.@email!='').
You can use the below condition in the 2nd if statement to check the email returned by the query is empty.
if(res.@email=="" || res.@email==undefied)
{
}
But, if the email passed in MEmail variable is not present in the recipient then you will not get @id in the return. so delivery will not get executed(as you have given the condition @id=res.@id).
Thanks,
Amit
You are right .. for 2nd Condition I should send delivery to email variable that we got
if(res.@email=="" || res.@email==undefied <mailto:res.@email==undefied> ) {
nms.delivery.QueueNotification('mediaconfirmation',
<delivery>
<targets>
<deliveryTarget>
<targetPart type='query' exclusion='false' ignoreDeleteStatus='false'>
<where>
<condition expr={'@email='+ctx.vars.MediaEmail}/>
</where>
</targetPart>
</deliveryTarget>
</targets>
</delivery>)
}
Views
Replies
Total Likes
You need to insert the email id in the recipient before sending the delivery as delivery will not execute if the email id is not present in the recipient.
Views
Replies
Total Likes
Views
Replies
Total Likes
Use the below script.
var rcpt = <recipient xtkschema = "nms:recipient" _operation = "insert" email={ctx.vars.MEmail}/>;
try {
xtk.session.Write(rcpt);
} catch(e) {
}
Views
Replies
Total Likes
Let me give a try
however I was also thinking to pass MEmail variable to 2nd if (else) part of delivery and remove query from target part.
nms.delivery.QueueNotification('mediaconfirmation',
<delivery>
<targets>
<deliveryTarget>
<targetPart exclusion='false' ignoreDeleteStatus='false'>
<where>
<condition expr={"@email='"+ctx.vars.MediaEmail+"'"}/>
</where>
</targetPart>
</deliveryTarget>
</targets>
</delivery>)
Views
Replies
Total Likes
@AmitNope insert idea seems did not worked
if(res.@email!=''){
nms.delivery.QueueNotification('mediaconfirmationwid',
<delivery>
<targets>
<deliveryTarget>
<targetPart type='query' exclusion='false' ignoreDeleteStatus='false'>
<where>
<condition expr={'@id ='+ res.@id}/>
</where>
</targetPart>
</deliveryTarget>
</targets>
</delivery>)
} else
{
var rcpt = <recipient xtkschema = "nms:recipient" _operation = "insert" email={ctx.vars.MediaEmail}/>;
xtk.session.Write(rcpt);
nms.delivery.QueueNotification('mediaconfirmation',
<delivery>
<targets>
<deliveryTarget>
<targetPart type='query' exclusion='false' ignoreDeleteStatus='false'>
<where>
<condition expr={'@email='+ctx.vars.MediaEmail}/>
</where>
</targetPart>
</deliveryTarget>
</targets>
</delivery>)
}
Views
Replies
Total Likes
Try below condition in else part.
<where>
<condition expr={"@email='"+ctx.vars.MediaEmail+"'"}/>
</where>
Views
Replies
Total Likes
Hi @Prasanna_Soni,
Were you able to resolve this query or do you still need more help here? Do let us know.
Thanks!
Views
Replies
Total Likes
//Defined getIfExists
var query = xtk.queryDef.create(
<queryDef schema="nms:recipient" operation="getIfExists">
<select>
<node expr="@email"/>
<node expr="@id"/>
</select>
<where>
<condition expr={"@email='"+ctx.recipient.@email+"'"}/>
<condition expr={"@sourceType='Media'"}/>
</where>
</queryDef>
)
var res = query.ExecuteQuery()
//Run the query
var res = query.ExecuteQuery()
//Called if statement worked
if(res.@email.length()>0){
nms.delivery.QueueNotification
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies