Custom Lookup method for TextAPI
To discuss or ask questions about this article, select the discussion tab above.
Overview
In text_api.cfg you can configure new attributes, which can be used in structured emails to create or modify SD objects. And the definition of a new attribute can use lookup method to convert some text field (i.e. user login) to object ID. A list of all standard conversion methods is in CMDB Administration Guide in chapter Conversion methods on page 189 in R12.1 documentation. And this article describes how to develop custom lookup method.
Procedures
Step 1. Create Spell method
First at all create free spell method (not connected to any object) with 4 parameters:
- string value - string value to convert
- string obj_name - name of object to which the returned value will be set
- object obj - real object to which the returned value will be set
- string attribute - name of attribute to which the returned value will be set
Here is the example for custom lookup_cnt_by_phone method: <source lang="javascript"> uuid lookup_cnt_by_phone(string phone, string obj_type, object obj, string attribute) { string method; method = "lookup_cnt_by_phone"; uuid contact;
logf(MILESTONE, "%s: Entering method: %s", method, phone); logf(VERBOSE, "%s: obj_type=%s", method, obj_type); logf(VERBOSE, "%s: attribute=%s", method, attribute); logf(VERBOSE, "%s: obj.id=%s", method, obj.id);
contact = (uuid)expand(format("&{'%s' = cnt.phone_number->id}", phone)); if (is_null(contact)) logf(MILESTONE, "%s: User not found", method); else logf(MILESTONE, "%s: User found: %s", method, contact);
return contact; } </source>
Step 2. Update configuration in text_api.cfg
To text_api.cfg configuration file insert this line after the last row begining with REQUEST: <source lang="ini"> REQUEST.CUSTOMER_PHONE=customer.UUID.lookup_cnt_by_phone </source>
Finally restart Service Desk service.