You are here: Custom Attributes > createTemplateAttribute

Create Template Attribute

Description

Create a custom attribute using the parameters provided.

Default Protocol Method Type URI
HTTPS POST createTemplateAttribute.xml

Post Parameters

Parameter Description Valid Values Optional
templateType

EMS Entity for which you want to define a custom attribute. Possible values are:

  • 1(Feature)
  • 2(Product)
  • 4(Customer)
  • 5(Contact)
  • 6(Entitlement)
Integer No
attrName Name of the custom attribute. String No
dataType

Data Type of the custom attribute. Possible values are:

  • 1(STRING)
  • 2(DATE)
  • 3(NUMERIC)
  • 4(BOOLEAN)
Integer No
defaultValue Specifies a default value of the custom attribute. String Yes
descr Description of the custom attribute. String Yes
optional

Indicates that the field is mandatory or optional.

Valid values are True or False.

Boolean No
regEx

Regular Expression that you want to use for validating the custom attribute values.

For example, the following regular expression helps validate the E-mail Address custom attribute:

^([a-zA-Z0-9\xA0-\xFF_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\xA0-\xFF\-]+\.)+))([a-zA-Z\xA0-\xFF]{2,4}|[0-9]{1,3})(\]?)$
String Yes

Sample Code

import java.io.IOException;
//..............................
//..............................
//..............................
import org.apache.http.params.HttpParams;
public class EMSSample {
	private static DefaultHttpClient httpclient = new DefaultHttpClient();
	private static Principal principal = null;
	//..............................
	//..............................
	//..............................
	public static String createTemplateAttribute.xml()throws Exception {
		if(!verifyLogin()){
			return "login failed";
		}
		HttpContext context = new BasicHttpContext();
		context.setAttribute(ClientContext.USER_TOKEN, principal);
		HttpPost post =  new HttpPost("https://localhost:8443/ems/3.6/createTemplateAttribute.xml");
		List<NameValuePair> nvps = new ArrayList<NameValuePair>();
		nvps.add(new BasicNameValuePair("dataType", "1"));
		nvps.add(new BasicNameValuePair("templateType", "1"));
		nvps.add(new BasicNameValuePair("optional", "true"));
		nvps.add(new BasicNameValuePair("attrName", "Custom"));
		nvps.add(new BasicNameValuePair("defaultValue", "test"));
		nvps.add(new BasicNameValuePair("descr", "sample"));
		nvps.add(new BasicNameValuePair("regEx", ""));
		post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
		HttpResponse response = httpclient.execute(post, context);
		HttpEntity entity = response.getEntity();
		byte[] b = null;
		if (entity != null) {
			long l = entity.getContentLength();
			b = new byte[(int) l];
			entity.getContent().read(b);
			entity.consumeContent();
		}
		return new String(b);
	}
}
 

Sample Response

<?xml version="1.0" encoding="UTF-8"?>
<emsResponse>
   <attribId>1</attribId>
   <stat>ok</stat>
</emsResponse>
See Also:

Output Format for Failure

Error Codes

Error Code Description
100 Invalid request parameter.
102 Invalid data entered.
107 An internal error occurred! Please report the error to System administrator.
113 Specify a valid Boolean value for {field}. Valid values are true or false. [Note: This error code is applicable for the fields - fetchCompleteEID, loginAllowed, isEnabled, vmEnabled, clonePotection, and optional.].
115 Length of {field} is {actual value}. It cannot be more Than {max value}. [Note: This error code is applicable for the fields - billAddr, billAddrCity, billAddrCountry, billAddrState, billAddrZip, shipAddr, shipAddrCity, shipAddrCountry, shipAddrState, shipAddrZip, refId1, refId2, contactPassword, description, and default value.]
120 {field} value is less than the minimum permitted value {value}. [Note: This error code is applicable for the fields - productd, featureId,entId, billType, lmId, lastModified, timeZoneId, customerId, and granularity.]
122 {field} is a required field and should have a not null value. [Note: This error code is applicable for the fields - Eid, namespaceName, featureName, startDate, endDate, userIds, featureId, productName, productVersion, detailsLM, lmId, templateType, customAttribute, lineItemId, customerRefId, granularity, loginId, oldPassword, and newPassword.]
711 Invalid Template Type!
713 Invalid Boolean value {value} passed. Provide a valid value(0 or 1).
714 Invalid Numeric value(x) passed. Please provide a valid value.
715 Invalid Date value(x) passed. Please provide a valid value(in yyyy-mm-dd format).
716 No data type exists for the value (value).
1081 Invalid Web service version provided
1084 No Web service version provided
1086 template attribute (x) already exists. Try again with a different name.
1088 The EMS system is running on HTTPS. Please provide the correct Web service URL.