Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

getIfExists results and based on that if and else in Script activity

Avatar

Avatar
Validate 1
Level 2
Prasanna_Soni
Level 2

Like

1 like

Total Posts

67 posts

Correct Reply

2 solutions
Top badges earned
Validate 1
Ignite 1
Give Back
Affirm 1
View profile

Avatar
Validate 1
Level 2
Prasanna_Soni
Level 2

Like

1 like

Total Posts

67 posts

Correct Reply

2 solutions
Top badges earned
Validate 1
Ignite 1
Give Back
Affirm 1
View profile
Prasanna_Soni
Level 2

26-04-2021

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. 

 

 

View Entire Topic

Avatar

Avatar
Boost 3
Level 3
Amit_Shinde
Level 3

Likes

22 likes

Total Posts

17 posts

Correct Reply

11 solutions
Top badges earned
Boost 3
Boost 1
Affirm 3
Affirm 1
View profile

Avatar
Boost 3
Level 3
Amit_Shinde
Level 3

Likes

22 likes

Total Posts

17 posts

Correct Reply

11 solutions
Top badges earned
Boost 3
Boost 1
Affirm 3
Affirm 1
View profile
Amit_Shinde
Level 3

26-04-2021

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

 

Prasanna_Soni

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>)

}

Amit_Shinde

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.

Prasanna_Soni
Yes that make sense and Recipient will be email address from Variable @MEmail .. But how do i insert that i am not sure.
Amit_Shinde

Use the below script.

 

var rcpt = <recipient xtkschema = "nms:recipient" _operation = "insert" email={ctx.vars.MEmail}/>;

try {
xtk.session.Write(rcpt);

} catch(e) {

}

Prasanna_Soni

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>)

Prasanna_Soni

@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>)


}

Amit_Shinde

Try below condition in else part.

 

<where>

<condition expr={"@email='"+ctx.vars.MediaEmail+"'"}/>

</where>