cancel
Showing results for 
Search instead for 
Did you mean: 

How to validate the incoming field value and raise an alert message

Former Member
0 Kudos

Dear all,

I have the following structure

If incoming value for the field externalid is empty then i have to raise a alert message to end user "externalid field is empty for the id : id number" and for all incoming values it should work. I used the following udf on field externalid with two arguments

if(externalid.equals(""))

{

throw new RuntimeException("externalid field empty for the following id : " +id);

}

else

{

return externalid;

}

This is working fine for single record. But for many records(multiple occurences), this logic is not working as if records 2 and 3 fails it is showing exception externalid field is empty for the id : record 2.

how to achieve the tranformation logic ?

Regards

Koti Reddy

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello,

Try this:

execution type: all values of a conext

Input: externalid, id

for(int i=0;i<externalid.length;i++)

{

if(externalid[i].equals(""))

{

throw new RuntimeException("externalid field empty for the following id : " +id[i]);

}

else

{

result.addValue(externalid);

}

}

Note - check for syntax errors

Thanks

Amit Srivastava

Former Member
0 Kudos

Hi Koti,

You can use Amit's udf ,but make sure the below .

1)Context of externalid should be at top level (all values in single array)

2)Use Mapwithdefault b/w externalid and udf

Regards

Venkat

Former Member
0 Kudos

Hi Amit,

I have tried the above udf, but still stuck-up.

For the above structure shown in image, i have tested giving the following payload

<?xml version="1.0" encoding="UTF-8"?>

<ns0:upsertRequest xmlns:ns0="http://sap.com/xi/SFIHCM01">

   <sessionId/>

   <upsert>

      <type/>

      <sfobject>

         <id>1</id>

         <businessKeys>1</businessKeys>

         <type>1</type>

         <status>1</status>

         <externalId>1</externalId>

         <username>1</username>

         <firstName>1</firstName>

         <lastName>1</lastName>

         <mi>1</mi>

         <gender>1</gender>

         <email>1</email>

         <managerExternalId>1</managerExternalId>

         <hrExternalId>1</hrExternalId>

         <department/>

         <jobCode/>

         <division/>

         <location/>

         <timeZone>1</timeZone>

         <hireDate/>

         <empId/>

         <title/>

         <businessPhone/>

         <fax/>

         <addressLine1/>

         <addressLine2/>

         <city/>

         <state/>

         <country/>

         <zipCode/>

         <reviewFreq/>

         <lastReviewDate/>

         <matrixManagerExternalIds/>

         <defaultLocale/>

         <customManagerExternalIds/>

         <secondManagerExternalId/>

         <loginMethod/>

         <proxy/>

      </sfobject>

      <sfobject>

         <id>2</id>

         <businessKeys>2</businessKeys>

         <type>2</type>

         <status>2</status>

         <externalId>2</externalId>

         <username>2</username>

         <firstName>2</firstName>

         <lastName>2</lastName>

         <mi>2</mi>

         <gender>2</gender>

         <email>2</email>

         <managerExternalId>2</managerExternalId>

         <hrExternalId/>

         <department/>

         <jobCode/>

         <division/>

         <location/>

         <timeZone/>

         <hireDate/>

         <empId/>

         <title/>

         <businessPhone/>

         <fax/>

         <addressLine1/>

         <addressLine2/>

         <city/>

         <state/>

         <country/>

         <zipCode/>

         <reviewFreq/>

         <lastReviewDate/>

         <matrixManagerExternalIds/>

         <defaultLocale/>

         <customManagerExternalIds/>

         <secondManagerExternalId/>

         <loginMethod/>

         <proxy/>

      </sfobject>

      <processingParam>

         <name/>

         <value/>

      </processingParam>

   </upsert>

</ns0:upsertRequest>

No node is creating for success records, instead it throws exception that "externalid field is missing for the id": id     for empty externalid field value in second record.

But my requirement is..... when i process 50 records, records with missing value for field externalid should raise an alert message to end user intimating him to check the externalid field for particular id. If the value for externalid field is present in incoming record/payload, then it should be passed to target system.

How can i implement this logic ?

Regards

Koti Reddy

Former Member
0 Kudos

Hi Venkat,

Please once again go through my post that i have replied to Amit and please provide your input

Regards

Koti Reddy

former_member184720
Active Contributor
0 Kudos

Hi Koti -

If you would like to send successfull records to target system and failed records as email in a single message then you can go with the below approach.

http://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=90570965

Former Member
0 Kudos

Hello,

I haven't tested above UDF but it should work. Can u show me ur display queue output?

In addition to that, u cannot output all the missed externalid using this UDF, becoz as soon as the function finds out first missed value it will fail the mapping.

Thanks

Amit Srivastava

Former Member
0 Kudos

Hi,

Sorry I missed your reply to Amit.

As per your requirement need to do few changes in Amit's code ,that is enough

String body ;

int count =0

for(int i=0;i<externalid.length;i++)

{

if(!externalid[i].equals(""))

{

result1.addValue("");  //populating value to your target structure

}

else

{

count =1;

body = body + "externalid field empty for the following id : " +id[i]) +"/n"

}

}

if(count == 1)

{

result2.addValue("");// open mail segment or MT

result3.addValue(body);// pass this to content

}

Regards

Venkat

Former Member
0 Kudos

Hi,

You have 2 options 1)3 mappings 2)As above said by Hareesh handle it in udf .

I personally recommend below option.

1)Using enhanced receiver determination check the conditions and open ur receiver as per your validations.

2)Mapping1 b/w source and target (based on validation)

3)Mapping2 b/w source and mail (based on validation)

I think my udf will be suitable for second approach.

For  1st approach split the udf into two.

Regards

Venkat

iaki_vila
Active Contributor
0 Kudos

Hi Koti,

You need to change the UDF with all values in queue and to do a FOR in order to get all the values incorrects.

Regards.

Former Member
0 Kudos

Hi Inaki,

"to do a FOR in order to get all the values incorrects "

I cant get you. Can you please elaborate

Regards

Koti Reddy

former_member191435
Contributor
0 Kudos

Hi Koti,

In the UDF dont use value as a single value.. use all values of context then try...

It will work...

Thanks,

Sreenivas.

iaki_vila
Active Contributor
0 Kudos

Hi Koti,

Correct me if im wrong, do you need to concatenate all the IDs that are wrong in a single exception?.

If im right you need to work with the UDF execution type, check this wiki UDF Execution Type - Context and Queue. - Process Integration - SCN Wiki

The idea is to check all the values for a determinate tag in one UDF execution, am i right?

Regards.