Recalling ads

Build 1501 on 14/Nov/2017  This topic last edited on: 24/Oct/2016, at 14:37

This topic describes the mechanism to "recall ads" in GN4. It may happen that an ad, that has already logged to GN4, is recalled for changes. The ad may already be on a page, so it is necessary to invalidate it so that the page cannot be printed.

This is achieved by a code workflow.

Basically, the workflow loads a XML file like:

<?xml version="1.0"?>

<img 

   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

   xmlns="urn:schemas-teradp-com:gn4tera" 

   name="3146936"><!-- CONFIGURE HERE THE URN OF THE AD -->

   <!-- Optional: -->

   <folderRef>

      <keyVal>/Daily Bugle/Pictures/Ads</keyVal>

   </folderRef>

</img>        

The <img> tag contains the name (URN) of the ad and it may contain the folderRef of where the image is, but this is not necessary. If the folderRef is not specified, the workflow must receive the parameter AdsFolder which will determine where in GN4 the advert is.

The workflow loads the XML then calls an importXml action applying to it a XSL:

<img name="{@name}" 

   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 <xsl:if test="$pars and $pars/*/add[@key='MakeDummy'] and $pars/*/add[@key='MakeDummy']/@value='true'">

    <xsl:attribute name="source"/><!-- empty source, make picture dummy --> 

  </xsl:if>

<!-- Note: if the parameter 'AdsFolder' is not specified

  and the input file doesn't contain the <folderRef> node,

  GN4 will error with the following message:

  'The loaded object is missing one or more fields needed to determine its access permissions' -->

    <xsl:choose>

      <xsl:when test="$pars and $pars/*/add[@key='AdsFolder']">

        <folderRef>

          <keyVal><xsl:value-of select="$pars/*/add[@key='AdsFolder']/@value"/></keyVal>

        </folderRef>

       </xsl:when>

       <xsl:otherwise><xsl:copy-of select="gn4:folderRef"/></xsl:otherwise>

    </xsl:choose>

    <!-- "trick" to remove low/thumbnail and preview from DB - to hide picture in results -->

    <low xsi:nil="true"/>

    <xsl:choose>

            <xsl:when test="$pars and $pars/*/add[@key='MakeDummy'] and $pars/*/add[@key='MakeDummy']/@value='true'">

   <thumbnail xsi:nil="true"/>

                <preview xsi:nil="true"/>

            </xsl:when>

            <xsl:otherwise>

               <thumbnail mime="image/png" size="11499">

              <data>iVBOR ... mCC</data>

                </thumbnail>

                <preview mime="image/jpeg" size="34808">

              <data>/9j/7QA ... B/9k=</data>

             </preview>

            </xsl:otherwise>

    </xsl:choose>

</img>

The workflow receives two optional parameters:

AdsFolder

MakeDummy

The picture can be reverted to a dummy, by removing the data, thumbnail and preview. The alternative is to make the image un-printable (by removing only the data element) but leaving it visible to the users. In this case, the preview and the thumbnail of the image is replaced with an image that ideally will say something like "This ad has been recalled". Please, note that the picture in the example workflow may not be suitable for your installation.

In this case, prepare an image and generate a thumbnail and preview (maybe by importing it into GN4). Then, get the binaries of the thumbnail and preview (as PNG or JPG) and encode them to Base64. There are many tools to do so, either to be installed on the PC, or online (like: http://www.opinionatedgeek.com/dotnet/tools/base64encode/). The encoded strings have to be inserted in the <data> tags of the thumbnail and preview and (this is important), the size of the binary file (the JPG/PNG) must be entered as the "size" attribute of the image (the red entry above). Also, the mime-type must be correct.

If the input file does not contain the GN4 folderRef (as this may not be known by the advertising system), this can be specified in the parameter AdsFolder.

The workflow can of course be used in a Back4 template.

Click to toggle expandThe workflow

The original topic is written by Marco Pusterla and can be found on http://forum.teradp.com/topic.asp?TOPIC_ID=855.