getIfExists results and based on that if and else in Script activity | Adobe Higher Education
Skip to main content
Prasanna_Soni
Level 4
April 26, 2021
해결됨

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

  • April 26, 2021
  • 3 답변들
  • 3703 조회

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. 

 

 

이 주제는 답변이 닫혔습니다.
최고의 답변: Prasanna_Soni

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

3 답변

Level 3
April 27, 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

 

Level 3
April 27, 2021

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.

Sukrity_Wadhwa
Community Manager
Community Manager
May 5, 2021

Hi @prasanna_soni,

Were you able to resolve this query or do you still need more help here? Do let us know.

Thanks!

Sukrity Wadhwa
Prasanna_Soni
Prasanna_Soni작성자답변
Level 4
May 12, 2021

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