Expand my Community achievements bar.

We are excited to introduce our latest innovation to enhance the Adobe Campaign user experience — the Adobe Campaign v8 Web User Interface!
SOLVED

Custom Method for default value in Campaign Schema

Avatar

Level 4

Hello All,

I am on Adobe Campaign v8, and trying to use a custom method for the default attribute

===========
Schema Name - fIdGen
==============
<attribute label="FName" name="fname" type="string"/>
<attribute default="genId(@fname)" label="FId" name="fId" type="string"/>

<methods>
 <method library="abc:commonFunc.js" name="genId" static="true">
  <parameters>
    <param desc="fname" inout="in" name="fName" type="string"/>
    <param desc="fId" inout="out" name="fId" type="string"/>
  </parameters>
 </method>
</methods>

==========================
abc:commonFunc.js
==========================
function abc_fIdGen_genId(fName){ 
  return "AC101444";
}

The above when executed gives me the error

 

XTK-170016 You are not authorized to use SQL expressions. 'genId' cannot be processed. XTK-170006 Unable to parse expression 'genId(@fName)'

. I need to take the Input fname later and create a Id.

 

Please help me in the same

 

Regards,

DG 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hello @dipendu_g ,

 

As I understood, you want, when someone enter the "fname" value in the input form then Unique "fId" will generate automatically when someone save the input form.

 

For this, I did the following test.

 

Schema: There you need to add following two fields and need to define a method:

 

 

<srcSchema _cs="Test01 (cus)" createdBy-id="0"
           entitySchema="xtk:srcSchema" img="xtk:schema.png" label="Test01" 
           mappingType="sql" md5="5CA41EE99322B61D35A2210A9D7956BB" modifiedBy-id="0"
           name="test01" namespace="cus" xtkschema="xtk:srcSchema">

  <element autopk="true" label="Test01" name="test01">

    <attribute label="FName" name="fname" type="string"/>
    <attribute label="FId" name="fId" type="string"/>

  </element>

  <methods>
    <method library="cus:test01.js" name="genId" static="true">
      <parameters>
        <param desc="fname" inout="in" name="fname" type="string"/>
        <param desc="fId" inout="out" name="fId" type="string"/>
      </parameters>
    </method>
  </methods>
</srcSchema>

 

 

JavaScript  Library: You need to create a .js file under JavaScript code folder in admin.

 

 

function cus_test01_genId(fname){ 
  var counter = getOption("counterForFid") // this is to mange the Id. You need to create it in option with int type. 
   setOption("counterForFid",++counter);
   
   return fname+counter; //it return unique Id
   
}

 

Parvesh_Parmar_2-1679490007913.png

 

 

Option: To mange  a unique fId, you need counter. If someone can enter same fName the it will keep fid unique.

 

Parvesh_Parmar_1-1679489540474.png

 

Input form:  There when someone enter the  value for "fname" field, it will pass to the function and it will return the unique fId based on fName. Note: There fname is passed to function via soap call and output of function is inserter to fId via xpathOut parameter.FId filed is read only, because this is id.

 

 

<form _cs="test01 (cus)"   entitySchema="xtk:form"
      img="xtk:form.png" label="test01"
      modifiedBy-id="3524" name="test01" namespace="cus" xtkschema="xtk:form">

  <input readOnly="true" xpath="@fId"/>
  <input xpath="@fname"/>

  <leave>
    <soapCall name="genId" service="cus:test01">
      <param exprIn="@fname" type="string"/>
      <param type="string" xpathOut="@fId"/>
    </soapCall>
  </leave>


</form>

 

 

Navigation hierarch: I believe you already created it. Just sharing if needed.

 

<navtree _cs="test01 (cus)"
         entitySchema="xtk:navtree" img="nl:folders.png" label="test01" 
         md5="AE43085ADF6D10668FDC881DCD8DDB64" modifiedBy-id="3524" name="test01"
         namespace="cus" xtkschema="xtk:navtree">

  <model name="root">
    <model label="Administration" name="admin">

      <model label="Test01" name="cusTest01">


        <nodeModel img="nms:folder.png" label="Test01" name="nmsFolder">
          <view name="listdet" schema="cus:test01" type="listdet">
            <columns>
              <node xpath="@fname"/>
              <node xpath="@fId"/>

            </columns>
          </view>
        </nodeModel>

      </model>
    </model>
  </model>


</navtree>

 

 

Final test: Enter Fname and save the value. Fid will be generated.

 

Parvesh_Parmar_3-1679490131649.png

 

I hope it will help you.

Thanks,

Parvesh

View solution in original post

10 Replies

Avatar

Community Advisor

Hello @dipendu_g 

 

Try changing the out parameter to something like this.

 <param desc="fId" inout="out" name="fId" type="string" xpathOut="/tmp/@tempFId"/>

 

Then change the default value of the attribute to:

<attribute default="[/tmp/@tempfId]" label="FId" name="fId" type="string"/>

 


     Manoj
     Find me on LinkedIn

Avatar

Level 2

Hi @Manoj_Kumar_ ,

 

I am getting the following error

Attribute 'xpathOut' unknown (see definition of element '/param' in schema 'Source schemas of entities (xtk:srcSchema)').

 

Regards,

DG

Avatar

Community Advisor

@dganguly 

Try this:

 <param type="string" xpathOut="/tmp/@tempfId"/>

 


     Manoj
     Find me on LinkedIn

Avatar

Community Advisor

Hello @dganguly 

 

You will have to add that code in the input form to make it work.

 

How are you ingesting records in the schema via a workflow or inut form?


     Manoj
     Find me on LinkedIn

Avatar

Level 2

Hi @Manoj_Kumar_ ,

 

I am ingesting using a form.

But the code you gave, when I add in the schema, it throws that error.

 

I am trying to get the next unique number, and so wanted to get it generated while the data is inserted in the table,

 

if 

 

Regards,

DG 

Avatar

Community Advisor

Hello @dipendu_g 

 

Here is another way to do it.

 

  1. Do not define the default value in the schema attribute. Instead, set the default value while the input form submission.
  2. In the input form, add a button to call the javascript function.

You can refer to this post for the code snippets: Solved: how to use javascript functions in input form - Adobe Experience League Community - 257268


     Manoj
     Find me on LinkedIn

Avatar

Correct answer by
Level 7

Hello @dipendu_g ,

 

As I understood, you want, when someone enter the "fname" value in the input form then Unique "fId" will generate automatically when someone save the input form.

 

For this, I did the following test.

 

Schema: There you need to add following two fields and need to define a method:

 

 

<srcSchema _cs="Test01 (cus)" createdBy-id="0"
           entitySchema="xtk:srcSchema" img="xtk:schema.png" label="Test01" 
           mappingType="sql" md5="5CA41EE99322B61D35A2210A9D7956BB" modifiedBy-id="0"
           name="test01" namespace="cus" xtkschema="xtk:srcSchema">

  <element autopk="true" label="Test01" name="test01">

    <attribute label="FName" name="fname" type="string"/>
    <attribute label="FId" name="fId" type="string"/>

  </element>

  <methods>
    <method library="cus:test01.js" name="genId" static="true">
      <parameters>
        <param desc="fname" inout="in" name="fname" type="string"/>
        <param desc="fId" inout="out" name="fId" type="string"/>
      </parameters>
    </method>
  </methods>
</srcSchema>

 

 

JavaScript  Library: You need to create a .js file under JavaScript code folder in admin.

 

 

function cus_test01_genId(fname){ 
  var counter = getOption("counterForFid") // this is to mange the Id. You need to create it in option with int type. 
   setOption("counterForFid",++counter);
   
   return fname+counter; //it return unique Id
   
}

 

Parvesh_Parmar_2-1679490007913.png

 

 

Option: To mange  a unique fId, you need counter. If someone can enter same fName the it will keep fid unique.

 

Parvesh_Parmar_1-1679489540474.png

 

Input form:  There when someone enter the  value for "fname" field, it will pass to the function and it will return the unique fId based on fName. Note: There fname is passed to function via soap call and output of function is inserter to fId via xpathOut parameter.FId filed is read only, because this is id.

 

 

<form _cs="test01 (cus)"   entitySchema="xtk:form"
      img="xtk:form.png" label="test01"
      modifiedBy-id="3524" name="test01" namespace="cus" xtkschema="xtk:form">

  <input readOnly="true" xpath="@fId"/>
  <input xpath="@fname"/>

  <leave>
    <soapCall name="genId" service="cus:test01">
      <param exprIn="@fname" type="string"/>
      <param type="string" xpathOut="@fId"/>
    </soapCall>
  </leave>


</form>

 

 

Navigation hierarch: I believe you already created it. Just sharing if needed.

 

<navtree _cs="test01 (cus)"
         entitySchema="xtk:navtree" img="nl:folders.png" label="test01" 
         md5="AE43085ADF6D10668FDC881DCD8DDB64" modifiedBy-id="3524" name="test01"
         namespace="cus" xtkschema="xtk:navtree">

  <model name="root">
    <model label="Administration" name="admin">

      <model label="Test01" name="cusTest01">


        <nodeModel img="nms:folder.png" label="Test01" name="nmsFolder">
          <view name="listdet" schema="cus:test01" type="listdet">
            <columns>
              <node xpath="@fname"/>
              <node xpath="@fId"/>

            </columns>
          </view>
        </nodeModel>

      </model>
    </model>
  </model>


</navtree>

 

 

Final test: Enter Fname and save the value. Fid will be generated.

 

Parvesh_Parmar_3-1679490131649.png

 

I hope it will help you.

Thanks,

Parvesh

Avatar

Level 2

Hi @Manoj_Kumar_  and @Parvesh_Parmar ,

 

Thanks both for the suggestion and @Parvesh_Parmar and detailing the solution for the Inputs forms so well.

 

Actually we need to call this from a WebForm, hence I initially tried with the default attribute along with a new SQL function.

 

The Code is based on current date, as FFYYDDMM001, FFYYDDMM002, etc for today, and next day again the counter starts with 001 ( FF is static piece)

 

Regards,

DG