Expand my Community achievements bar.

SOLVED

How to send an email through an javascript

Avatar

Level 2

Hi Jean,

I am trying to send an email using submit delivery method but getting an following error.

09/04/2018 09:35:41 SCR-160012 JavaScript: error while evaluating script 'WKF11540/js'.

09/04/2018 09:35:41 SOP-330011 Error while executing the method 'SubmitDelivery' of service 'nms:delivery'.

09/04/2018 09:35:41 DLV-490051 Failed to analyze delivery (identifier 'unknown').

09/04/2018 09:35:41 DLV-490050 The XML document to add to the scenario does not have a valid format.

09/04/2018 09:35:41 Element 'targetPart' is unknown (see definition of element '/targets' in schema 'Deliveries (nms:delivery)').

Can I pass targets and content inside submit delivery method?

Thanks

Naveen S

1 Accepted Solution

Avatar

Correct answer by
Level 2

Thanks Jean for you reply.

I have figured out in the script it was some variable issue.

You can close the ticket

Regards

Naveen

View solution in original post

11 Replies

Avatar

Level 2

Here is the code.

var abc = "<html><body><p>text</p></body></html>"

var deliveryId = nms.delivery.SubmitDelivery("DM79018",<delivery>

<targets >

    <deliveryTarget >

      <targetPart  exclusion='false'   ignoreDeleteStatus='false'>

        <where>

          <condition expr="@email = 'naveen@xyz.com'"/>

        </where>

      </targetPart>

    </deliveryTarget>

  </targets>                                  <content>

                                    <html>

                                      <source>{abc}</source>

                                    </html>

                                  </content>

                                </delivery>);

                               

                                logInfo(deliveryId)

Avatar

Level 4

I am trying your code to send delivery but its not working for me

 

nms.delivery.QueueNotification('mediaconfirmation',

<delivery>

<targets>

<deliveryTarget>

<targetPart exclusion='false' ignoreDeleteStatus='false'>

<where>

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

</where>

</targetPart>

</deliveryTarget>

</targets>

</delivery>)

Avatar

Level 10

Hi Naveen,

Please may you read the SubmitNotification method in the JSAPI.chm documentation, it is more detailed about the 3 possibilities for the target element than submitDelivery method (for which the documentation doesn't give any example, except one in JSON but not for target  part).

For instance, in the SubmitDelivery method, you can write:

<targets > 

    <deliveryTarget> 

        <targetPart> 

            <where filteringSchema="nms:recipient"> 

                <condition expr="@email = 'xxxx@yyyy.com'"/> 

            </where> 

        </targetPart> 

    </deliveryTarget> 

</targets >

Regards
J-Serge

Avatar

Level 10

oh your 2nd post and mine have been posted simultaneously

annother example, if you must use it within a webApp Javascript activity:

nms.delivery.QueueNotification('internal-name-of-delivery',

<delivery>

  <targets>

    <deliveryTarget>

      <targetPart type='query' exclusion='false' ignoreDeleteStatus='false'>

        <where>

          <condition expr={'@id ='+ ctx.recipient.@id}/>

        </where>

      </targetPart>

    </deliveryTarget>

  </targets>

</delivery>);

Regards

JS

Avatar

Level 10

Hi naveens,

Please may you add the missing attribute in targetPart:

type='query'

Regards

JS

Avatar

Level 2

After adding type="query" In submitDelivery its not working but it works in submit notification but I need feed content as well.

Avatar

Level 10

Hi Naveens,

SubmitNotification method is only useful for continuous deliveries (adding new target contacts, not for changing the delivery content).

I mentioned it because of the 2 other methods described in the documentation for target feed (external file etc).

It is weird why an error still occurs after type='query' added. Sorry I don't undertand. Is the mistake the same?
Is your delivery DM79018 a standard one, or recurrent one, or continuous one ?

(in that latter case, again it is Submit Notification that must be used, but with no content change.)

Can you copy/paste the xml code in a text editor (such as Notepad++, Ultraedit, etc) in order to see if you have special characters in it, not visible/shown as blank char?

Please may you try also with :

            <where filteringSchema="nms:recipient"> 

                <condition expr="@email = 'xxxx@yyyy.com'"/> 

Regards

JS

Avatar

Level 2

Hi Jean,

I have created a template and utilizing that template internal name and trying to target population dynamically by passing email through variable and content too dynamic.

I have removed type="query" and Submitdelivery its working fine now but I couldn't be able to pass email address has a variable inside experssion.

here is the code

var abc = "<html><body><p>xxx</p></body></html>"

var emailId = "abc.xyz@yyy.com"

var deliveryId = nms.delivery.SubmitDelivery("DM79018",<delivery>

<targets >

    <deliveryTarget >

      <targetPart    exclusion='false'  ignoreDeleteStatus='false'>

        <where>

          <condition expr={'@email=' +emailId}/>

        </where>

      </targetPart>

    </deliveryTarget>

  </targets>

                                  <content>

                                    <html>

                                      <source>{abc}</source>

                                    </html>

                                  </content>

                                </delivery>);

                               

                                logInfo(deliveryId)

Avatar

Correct answer by
Level 2

Thanks Jean for you reply.

I have figured out in the script it was some variable issue.

You can close the ticket

Regards

Naveen

Avatar

Level 2

can you share your code i am going through same issue