Important Update: Some Community URL Redirects are Under Maintenance. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Object to Add a VL Value

AndreaDollen
Contributor III

Hi All,

 

I need fresh eyes on this!  I need to add a value to a values list when a record is saved (not select the value, but just add it to the list).  The value I need to add is the content ID of the record.  I have confirmed using console.log that my SessionToken is good, my VL ID is the id of the actual Values List and not the field, the content ID is correct, and my URL is correct.  I am getting a response of 0 (no errors though), so I think I need to put in an "onreadystatechange" something-or-other, but I don't know where I need to put it or what it should look like.  Can any of you super smart people like David Petty or Jeff Letterman help me out please?  My code is below.  For simplicity I only have the "Save" button portion in here.  I'll add the "Save and Close" once it works. 

 

P.S.  This is on 6.4HF1.  I know I'll need to change how I'm getting the base URL (maybe session token too?) in later versions, but for this one it works.

 

THANKS IN ADVANCE!!!

Andrea

 

<script type="text/javascript">

var sessionToken = parent.parent.ArcherApp.globals.workpointFeatures.SessionToken;
var baseURL = window.location.protocol + '//' + window.location.host + parent.parent.ArcherApp.globals['baseUrl'];
var xmlhttp = new XMLHttpRequest();
var vListId = 3462;

function addValue() {

console.log(sessionToken);
console.log(baseURL);
console.log(getRecordId());
console.log(vListId);

xmlhttp.open('POST', baseURL + '/ws/field.asmx', true);
xmlhttp.setRequestHeader('SOAPAction', 'http://archer-tech.com/webservices/CreateValuesListValue');
xmlhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');


// build SOAP request
var soapRequest = '<?xml version="1.0" encoding="utf-8"?>' +
'<soapenv:Envelope ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
'<soap:Body>' +
'<CreateValuesListValue xmlns="http://archer-tech.com/webservices/">' +
'<sessionToken>' + sessionToken + '</sessionToken>' +
'<valuesListId>' + vListId + '</valuesListId>' +
'<valuesListValueName>' + getRecordId() + '</valuesListValueName>' +
'</CreateValuesListValue>' +
'</soap:Body>' +
'</soap:Envelope>'

xmlhttp.send(soapRequest);

console.log(soapRequest);
console.log(xmlhttp.status);
console.log(xmlhttp.statusText);

$("#master_btnApply").click()
}


Sys.Application.add_load(function() {
// Hijack Save Button
$('#master_btnApply').clone().attr('id', 'master_customBtnApply').insertBefore('#master_btnApply');
$('#master_btnApply').hide();
$('#master_customBtnApply').unbind('click').prop('onclick', null).click(function(){ addValue('apply');return false; });
});
</script>

8 REPLIES 8

DavidPetty
Archer Employee
Archer Employee

Hi Andrea

 

Does the user have the ability to modify the values list?

 Advisory Consultant

Yes, currently it’s me, and I am a System Admin.

To be honest, I see a lot of issues in the code, starting from the scope visibility of variables and code structure all the way to incorrect SOAP request.

But you can start by fixing visibility of the variables, especially SOAP request and XMLHttp.

Then you need to make structure a bit linear, as some of the codes are never reached.

And yeah, SOAP request is a bit not correct as there is no declaration of soapenv element

Ilya Khen‌ Great!  We are in agreement that I am not good at this (I am not a trained coder) and I need help (which is why I am here).  I tried using examples from my own library, the community, Google, etc.  Can you help?  Do you have an example of using a Custom Object to add a value to a values list?

 

Andrea

David PettyJeff LettermanIlya Khen‌ I just realized the first one I posted was a version I didn't finish and quit and decided to get help here.  I corrected it to my last version that I thought was somewhat close and where I was receiving the response of 0.  Sorry about that!

Let us try to fix your code first   If step aside the structure issues, we can maybe do something like this:

 

However, mind that vListId IS NOT a field id you can see from Application Builder. It is internal id of the value list, and it has to be found from API call as well or App Builder Report, see page 152 "Determine IF of Value List" in the https://community.rsa.com/docs/DOC-97464 

<script type="text/javascript">
var sessionToken = parent.parent.ArcherApp.globals.workpointFeatures.SessionToken;
var baseURL = window.location.protocol + '//' + window.location.host + parent.parent.ArcherApp.globals['baseUrl'];
var vListId = 3462;
var xmlhttp = new XMLHttpRequest();
var soapRequest;


function prep() {
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
alert('New value added!');
$("#master_btnApply").click();
}
};

addValue();
xmlhttp.open('POST', baseURL + '/ws/field.asmx', true);
xmlhttp.setRequestHeader('SOAPAction', 'http://archer-tech.com/webservices/CreateValuesListValue');
xmlhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
xmlhttp.send(soapRequest);
}

function addValue() {

console.log(sessionToken);
console.log(baseURL);
console.log(getRecordId());
console.log(vListId);

// build SOAP request
soapRequest = '<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
'<soap:Body>' +
'<CreateValuesListValue xmlns="http://archer-tech.com/webservices/">' +
'<sessionToken>' + sessionToken + '</sessionToken>' +
'<valuesListId>' + vListId + '</valuesListId>' +
'<valuesListValueName>' + getRecordId() + '</valuesListValueName>' +
'</CreateValuesListValue>' +
'</soap:Body>' +
'</soap:Envelope>'

console.log(soapRequest);
}


Sys.Application.add_load(function() {
// Hijack Save Button
$('#master_btnApply').clone().attr('id', 'master_customBtnApply').insertBefore('#master_btnApply');
$('#master_btnApply').hide();
$('#master_customBtnApply').unbind('click').prop('onclick', null).click(function(){ prep(); return false; });
});
</script>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

YES!!!!!  That worked!!! 

 

Thanks Ilya Khen‌!  Very, very much appreciated!

 

Andrea

Anytime