We can create Contact fields Mandatory over COD solution .

Example : I am creating Phone & Email Fields Mandatory

Fig 1.1

Step 1 .  Create a Solution and give any name

Step 2.   Open Solution Explorer and right click and add new item ->select Business Object Extension ->  give it name : ContactFields_Ext ->Press Add

Step 3: Select fields as shown below

Step 4: Press Ok

Step 5: Right Click on ContactFields_Ext.xbo on Solution explorer and select Create Script File ->Select Validation On Save

Step 6: Press Ok

Step 7: Now Double click on ContactFields_Ext.xbo and write below code

import AP.Common.GDT;

import AP.FO.BusinessPartner.Global;

[Extension] businessobject AP.FO.BusinessPartner.Global:BusinessPartner raises Error_Msg_Phone , Error_Msg_Email , Error_Msg_Lname {

        // You must activate this business object before you can access the extension fields

        // or messages in script files, forms, and screens.

           node Common {

        element contact_ext  : ID = “1234”;

        message Error_Msg_Phone text “Please Enter Phone”;

        message Error_Msg_Email text “Please Enter Email”;

        message Error_Msg_Lname text “Please Enter Last Name “;

           }

}

Step 8: Now Double click on Validation On save   and

Write below Code :

import ABSL;

//Note :  This screen executed 5 time . For actual execution it return category code ‘1’ for Screen refresh it return category code ‘2’

// ——————— Code to make Contact field : Phone & Email Mandtory ———————————————————

// Get value ‘X’ for Phone field on Web UI

var lv_phone = this.CurrentDefaultIsContactPersonFor.BusinessPartnerRelationship.ContactPerson.ContactPersonWorkplaceAddressInformation.ContactPersonWorkplaceAddress.DefaultConventionalPhone.IsSet().ToString();

// Get value ‘X’ for Phone field on Web UI

var lv_email = this.CurrentDefaultIsContactPersonFor.BusinessPartnerRelationship.ContactPerson.ContactPersonWorkplaceAddressInformation.ContactPersonWorkplaceAddress.DefaultEMail.IsSet().ToString();

var catcode_phone = this.CategoryCode;   // get catogry code for phone “1” for actual execution and “2” for Screen refresh

var catcode_email = this.CategoryCode;  // get category code for Email “1” for actual execution and “2” for Screen refresh

var lc_phone = lv_phone ;  // pass phone field value ‘X’

var lc_email = lv_email ;  // Pass email field value ‘X’

var lc_add_phone ;  // additional phone variable

var lc_add_email ; //  // additional Email variable

//——-  Store Inforormation that whether Phone fieds is initial or not

if (lc_phone.Contains(“X”))

{

lc_add_phone = “X” ;

}

//—close–

//——-  Store Inforormation that whether email fieds initial or not

if (lc_email.Contains(“X”))

{

lc_add_email = “X” ;

}

//—close–

//——————– Start:  Logic to creating error message over UI if Email and Phone fields are Null

if (catcode_phone.Contains(“1”))

{ // 0001

if (this.Common.GetFirst().Person.Name.FamilyName.IsInitial())

{ //0002

raise Error_Msg_Lname.Create(“E”); // display error message for phone

return false;

} //0002

else

{ //0003

if (lc_phone.Contains(“X”)) // check if phone variable contain value if yes the return true

{ // —– 1

if (lc_email.Contains(“X”) ) // check if Email variable contain value if yes the return true

{ // — 1.1

return true;

} // —-1.1

else

{  //— 1.2

raise Error_Msg_Email.Create(“E”);

return false;

}  //— 1.2

}  //—– 1

else  //if phone and Email fields are blank

{ //—-  2

if ((lc_add_phone.IsInitial() && catcode_phone.Contains(“1”)) )  // check if phone or email fields are blank and there is actual execution

{ //—- 2.2

if (lc_add_email.IsInitial() && catcode_email.Contains(“1”) ) // check if email fields field is blank and it is actual execution Cat_code = ‘1’

{ //—–2.3

raise Error_Msg_Email.Create(“E”);  // display error message for Email

return false;

} //—–2.3

else

{ //—- 2.4

raise Error_Msg_Phone.Create(“E”); // display error message for phone

return false;

}  //—–2.4

} //——2.2

else

{ //—-2.5

if (lc_add_email.IsInitial() && catcode_email.Contains(“1”) ) // check if email fields field is blank and it is actual execution Cat_code = ‘1’

{ //—-2.6

raise Error_Msg_Email.Create(“E”);  // display error message for Email

return false;

}  //— 2.6

else

{ //—-2.7

return true;

}//—– 2.7

} //—– 2

}//—– 1

//——————– Close :  Logic to creating error message over UI if Email and Phone fields are Null

}//0002

}//0001

Step 9: Now Save and activate your Solution

Step 10 : Try To save you new contact detail without Phone and Email . It will give Error

I hope it would be helpful .

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply