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
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
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
}
Option: To mange a unique fId, you need counter. If someone can enter same fName the it will keep fid unique.
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.
I hope it will help you.
Thanks,
Parvesh
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"/>
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
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?
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Views
Replies
Total Likes
Hello @dipendu_g
Here is another way to do it.
You can refer to this post for the code snippets: Solved: how to use javascript functions in input form - Adobe Experience League Community - 257268
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
}
Option: To mange a unique fId, you need counter. If someone can enter same fName the it will keep fid unique.
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.
I hope it will help you.
Thanks,
Parvesh
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
Views
Replies
Total Likes