The CreatorCon Call for Content is officially open! Get started here.

Current Ticket Number in Record Producer

cnharris1
Kilo Sage

Good morning developers,

I'm sure there is an easy answer to this question but I have not been successful in figuring it out. My problem is that I'm building out a form using a record producer. I'm trying to capture the current ticket number that will be created once the user clicks submit and display it in info message. I am able to get the sys_id but I can't get the display value. I have used var req = current.sys_id.getDisplayValue(); but that's not working.

I've also tried using this: 

var agr                 =    new x_adosy_as.Agreement(current);
var req                 =    agr.record.number;

 

Here's the info message:

gs.addInfoMessage("Your Agreement Has Been Sent for Signature!"  + req);

Any help will be greatly appreciated!

 

Thanks,

 

 

chnarris

16 REPLIES 16

No problem, I'm using the Adobe Sign Integration and on the merge data section of my script, all of the information is being sent to a form in Adobe, which is working but I can't get the ticket number to show for some reason.

Here is my script:

(function() {
    
    //-----------------
    // Read variables
    //-----------------
    
    // Collect the information that we need from the variables filled in by the user
    var our_name = 'Tarrant County (TC) Information Technology Department (ITD) Requisition Request';
    
    var preparer           = producer.getDisplayValue('prepared_by');
    var to_date            = producer.date.getDisplayValue() + '';
    var po                 = producer.purchase_requisition_number.getDisplayValue() + '';
    
    var agr                 = new x_adosy_as.Agreement(current);
    var req                 = agr.number;
    
    var prev_po            = producer.previous_po_number.getDisplayValue() + '';
    var vendor_name        = producer.recommended_vendor_name.getDisplayValue() + '';
    var address            = producer.vendor_address.getDisplayValue() + '';
    var contact            = producer.vendor_contact.getDisplayValue() + '';
    var vendor_phone       = producer.contact_number.getDisplayValue() + '';
    var vendor_email       = producer.email.getDisplayValue() + '';
    var fund_center_1      = producer.fc1.getDisplayValue() + '';
    var fund_center_2      = producer.fc2.getDisplayValue() + '';
    var fund_center_3      = producer.fc3.getDisplayValue() + '';
    var cost_center_1      = producer.cc1.getDisplayValue() + '';
    var cost_center_2      = producer.cc2.getDisplayValue() + '';
    var cost_center_3      = producer.cc3.getDisplayValue() + '';
    var commitment_item_1  = producer.ci_1.getDisplayValue() + '';
    var commitment_item_2  = producer.ci_2.getDisplayValue() + '';
    var commitment_item_3  = producer.ci_3.getDisplayValue() + '';
    var project_line       = producer.project_line.getDisplayValue() + '';
    var requestor          = producer.requestor.getDisplayValue() + '';
    var requestor_phone    = producer.requestor_phone.getDisplayValue() + '';
    var quantity1          = producer.quantity_1.getDisplayValue() + '';
    var unit_type_1        = producer.unit_1.getDisplayValue() + '';
    var description_1      = producer.description_1.getDisplayValue() + '';
    var justification      = producer.justification.getDisplayValue() + '';
    
    
    var manager       = producer.itd_resource_manager.getDisplayValue() + '';
    //    var bus_manager   = producer.itd_business_services_manager.getDisplayValue() + '';
    //var manager_id    = producer.manager + '';
    //var manager_name  = producer.manager.getDisplayValue() + '';
    
    // Compose the information that we will send to Adobe Sign
    // This must be an object in field/value format
    // The field names MUST match those of the Document fields of the template
    var merge_data = {
 //Remove the last comma
  PreparedBy                        : preparer,
  TD                                : to_date,
  PurchaseReqNum                    : po,
        
  ReqTrackingNum                    : req,
        
  PreviousPONum                     : prev_po,
  ITDResourceMg                     : manager,
  VendorName                        : vendor_name,
  Contact                           : contact,
  Address                           : address,        
  VendorPhone                       : vendor_phone,        
  Email                             : vendor_email,    
  FundCenter1                       : fund_center_1,
  FundCenter2                       : fund_center_2,
  FundCenter3                       : fund_center_3,        
  CostCenter1                       : cost_center_1,     
  CostCenter2                       : cost_center_2,
  CostCenter3                       : cost_center_3,
  CommitmentItem1                   : commitment_item_1,
  CommitmentItem2                   : commitment_item_2,
  CommitmentItem3                   : commitment_item_3,
  ProjectLine                       : project_line,
  Requestor                         : requestor,
  RequestorPhone                    : requestor_phone,        
  Quantity1                         : quantity1,     
  UnitType1                         : unit_type_1,
  Description1                      : description_1,
  Justification                     : justification
    };
    
    //-------------------------
    // Set Adobe Sign objects
    //-------------------------
    
    // Create an Agreement object to allow us to add the Document and Signers
    var ag = new x_adosy_as.Agreement(current);
    
    // Hardcoded sys_id of the Document template for this Catalog Item
    var template_id = 'd95ffefedb3c5850918c2b35ca9619ca';

    // Add a Source document to the agreement and pass in the data to prefill its fields
    // (We can pass in either the sys_id of a template, or the sys_id of an attachment)
    //
    ag.addDocument(template_id,merge_data);

    // Add the two signers
    // (We can pass in either the sys_id of a user, or an email address as a string)
    //
    ag.addSigner(manager);
    //ag.addSigner(bus_manager);
    
    //---------------------
    // Set Agreement info
    //---------------------
    
    // Set the name of the Agreement record from the supplied 'name' variable
    current.name = our_name;

    // Set the URL that users will be redirected to after signing
    current.post_sign_uri = '/x_adosy_as_agreement.do?sys_id=' + current.sys_id + '&sysparm_view=x_adosy_as_end_user';

    // Set the agreement to 'Ready' to tell it to submit to AdobeSign after it is saved
    current.state = 'Ready';
    
    

})();
gs.addInfoMessage("Your Agreement Has Been Sent for Signature!"  + current.number);

Can you try by replacing last line of your code with below & confirm if state value is printed or not.


gs.addInfoMessage("Your Agreement Has Been Sent for Signature!"  + current.number +' state is  '+current.state);

Yes sir, state is Ready, popped up in the info message but I'm not sure why the ticket number isn't

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can add this in record producer script section; I assume your target table has number field

gs.addInfoMessage("Your Agreement Has Been Sent for Signature!"  + current.number);

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

I tried using that code in the record producer script section but the message didn't show up at all. My target table does have a number field that's named number but am I doing something wrong?

Thanks

 

cnharris