Savon Rails—How to pass multiple parameters? - savon

I have this code:
client = Savon.client(wsdl: wsdl)
response = client.call(:post, message: {
login: {
userName: username,
password: password
},
data: {
parameters: {
key: "firstName",
value: "Joe"
}
})
This works, but I need to send multiple parameters. If I have multiple parameters: {mydata} fields, it doesn't work because a hash must have unique keys...
How do I get Savon to send multiple parameter fields?

I still don't know the proper way, but the message parameter can be an XML string, so I ended up with the following solution:
client = Savon.client(wsdl: wsdl)
response = client.call(:post, message: build_xml)
def build_xml
"
#{login_xml}
<data>
<code>CUSTOMER_DETAILS</code>
" + test_data.map { |h| parameter_xml(h.first, h.last) }.join("") + "
</data>
"
end
def login_xml
"
<login>
<userName>#{#xml_username}</userName>
<password>#{#xml_password}</password>
</login>
"
end
def parameter_xml(key, val)
"
<parameters>
<key>#{key}</key>
<value>#{val}</value>
</parameters>
"
end

Related

I want to get recipient_signing_uri from the Docusign API response but it returns null

Here is the code
public function send(Request $request): object
{
$apiClient = new ApiClient();
$apiClient->getOAuth()->setOAuthBasePath(env('DS_AUTH_SERVER'));
try {
$accessToken = $this->getToken($apiClient);
} catch (\Throwable $th) {
return back()->withError($th->getMessage())->withInput();
}
$userInfo = $apiClient->getUserInfo($accessToken);
$accountInfo = $userInfo[0]->getAccounts();
$apiClient->getConfig()->setHost($accountInfo[0]->getBaseUri() . env('DS_ESIGN_URI_SUFFIX'));
$envelopeDefenition = $this->buildEnvelope($request);
try {
$envelopeApi = new EnvelopesApi($apiClient);
$result = $envelopeApi->createEnvelope($accountInfo[0]->getAccountId(), $envelopeDefenition);
dd($result);
} catch (\Throwable $th) {
return back()->withError($th->getMessage())->withInput();
}
return view('backend.response')->with('result', $result);
}
When I print $result variable it returns a response like this
container: array:8 [
"bulk_envelope_status" => null
"envelope_id" => "b634f8c5-96c5-4a18-947f-59418d8c4e03"
"error_details" => null
"recipient_signing_uri" => null
"recipient_signing_uri_error" => null
"status" => "sent"
"status_date_time" => "2023-02-16T07:24:39.1570000Z"
"uri" => "/envelopes/b634f8`your text`c5-96c5-4a18-947f-59418d8c4e03"
]
I want to get the value of recipient signing uri in response but in my case it returns null
How I can achieve this? Will anyone suggests?
createEnvelope creates the envelope. It does not give you an URL for an embedded recipient view (signing ceremony). In order to get that URL, you need to make an additional call to
EnvelopeViews:createRecipient/
See this page for more info.
Also
$apiClient->getConfig()->setHost($accountInfo[0]->getBaseUri() . env('DS_ESIGN_URI_SUFFIX'));
You are using the first entry in the UserInfo returned data's accountInfo array. That's not a good idea. Instead, look for the entry that is the user's default account.
Or if your application is designed to work with a specific eSign account, then make sure the user has access to that account.
It is very common for DocuSign customers to have access to more than one account.

Permission of ir.config_paramenter in odoo 12

I got this problem. Why i get this access error and how can i fix it?
Odoo Server Error - Access Error
Sorry, you are not allowed to access
this document. Only users with the following access level are
currently allowed to do that:
Administration/Settings
(Document model: ir.config_parameter) - (Operation: read, User: 21)
Here is my code:
Button submit:
<button string="Confirm" name="button_submit" states="draft" type="object" class="oe_highlight"/>
My python code:
def send_email(self, subject, message_body, email_from, email_to):
template_obj = self.env['mail.mail']
template_data = {
'subject': subject,
'body_html': message_body,
'email_from': email_from,
'email_to': email_to
}
template_id = template_obj.create(template_data)
template_obj.send(template_id)
template_id.send()
#api.multi
def request_recuitment_send_mail(self):
""" Send mail with wizard """
base_url = request.env['ir.config_parameter'].get_param('web.base.url')
base_url += '/web#id=%d&view_type=form&model=%s' % (self.id, self._name)
subject = '''Request recuitment for {}'''.format(self.job_id.name)
message_body = '''
<div style="font-size: medium;">
Dear {},
Please check this link for more information Click here
'''.format(
self.user_id.name,
base_url,
)
email_from = '''HR Recruiment <{}>'''.format(self.approver_id.work_email)
email_to = self.user_id.email
self.send_email(subject, message_body, email_from, email_to)
#api.multi
def button_approve(self):
subject = "Request recruitment for {self.job_id.name} has been approved "
body = '''
Position Request: {}
Quantity of Position: {}
Department: {}
Expected Gross Salary: {}
'''.format(
self.job_id.name,
self.quantity,
self.department_id.name,
self.salary_cross_expected
)
self.env['mail.message'].create({'message_type': "notification",
"subtype": self.env.ref("mail.mt_comment").id,
'body': body,
'subject': subject,
'needaction_partner_ids': [(4, self.user_id.partner_id.id,)],
'model': self._name,
'res_id': self.id,
})
self.request_recuitment_approved_send_mail()
self.write({'state': 'approved'})
It should be safe to use sudo() in this case:
request.env['ir.config_parameter'].sudo().get_param('web.base.url')
"Normal" Users don't have any rights on model ir.config_parameter (System parameters). Only the admin (one of its default access groups) or the superuser can read such parameters.
About sudo([flag=True]) from the current documentation (Odoo 15):
Returns a new version of this recordset with superuser mode enabled or disabled, depending on flag. The superuser mode does not change the current user, and simply bypasses access rights checks.
IMPORTANT: I'm not completely sure when it was changed, but IIRC the "current user change" was removed since Odoo 13. So for Odoo 12 sudo will change the current user, which for example will have impacts on default values on creation, created message authors, and so on.
In your case that's irrelevant, because you're only getting the base url or the parameter value, and that's it.

error updating SQL table through HTML form

i have been stuck on this for a little while now i am updating a SQL table through a form in HTML, via PHP and i have the request working when i manually enter the values however when i use $_POST it doesnt work and comes up with a syntax error. i am fairly new to SQL and really appreciate any help given.
//$sql = "UPDATE personnel SET firstName='Lawo', lastName='Fish', email='someThing#aol.col', jobTitle='' WHERE id=4";
$sql = "UPDATE personnel SET firstName=" . $_POST['fname'] . ", lastName=" . $_POST['lname'] . ", email=" . $_POST['email'] . ", jobTitle= " . $_POST['job'] . " WHERE id=" . $_REQUEST['personID'];
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();```
this is my AJAX in script:
```updateFunc.addEventListener('click', function(e) {
fName = document.getElementById('txtFirstName').value;
lName = document.getElementById('txtLastName').value;
email = document.getElementById('txtEmail').value;
job = document.getElementById('txtJobTitle').value;
console.log(job);
$.ajax({
url: "PHP/update.php",
type: 'POST',
dataType: 'json',
data: {
personID: personID,
fname: fName,
lname: lName,
email: email,
job: job,
},```

typeahead bootstrap3: how to pass a parameter into remote?

I am trying to use typeahed twitter for bootstrap
https://github.com/twitter/typeahead.js
I need to change the remote dynamically according to what user types in and ANOTHER parameter.
(The goal is to retrieve the cities of a country)
trying with country="en"; does not affect it
trying with autocompleter.remote=".."; does not work.
Any idea ?
<script>
var country="fr";
var autocompleter = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: 'ajax.php?action=getVilles&country='+country+'&ville=%QUERY'
});
autocompleter.initialize();
$('#city').typeahead(null, {
name: 'city',
displayKey: 'city',
source: autocompleter.ttAdapter()
});
</script>
This is what I've done:
var tagStudies = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('text'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "autocomplete/study",
replace: function(url, uriEncodedQuery) {
study = $('#study').val();
ssp = $("#social-security").val();
return url + '?q=' + uriEncodedQuery + '&s=' + study + '&ssp=' + ssp
},
filter: function (parsedResponse) {
return parsedResponse.studies;
}
}
});
Take a look at the replace function. The first parameter is the url, and the second is what the user is typing. I made a concatenation to pass the query and 2 extra params.
If you copy the code, make sure you replace 'text' for 'value' in datumTokenizer. Hope it helps

How do I send an additional parameter to a function?

I have this code which displays text from a Web SQL database:
<span contenteditable="true"
onkeyup="updateRecord('+item['id']+', this)">' + item['product'] + '</span>
When I edit the text it calls the updateRecord function and updates the value.
function updateRecord(id, textEl) {
db.transaction(function(tx) {
tx.executeSql("UPDATE products SET product = ? WHERE id = ?",
[textEl.innerHTML, id], null, onError);
});
}
I have several of these values I'm trying to work with though. So I would like to specify the column. The above code works if I set the column to product in the function, in the following code I'm trying to send an additional parameter to the function but it's not working. What am I doing wrong here?
<span contenteditable="true"
onkeyup="updateRecord('+item['id']+', 'product', this)">'+ item['product'] + '</span>
function updateRecord(id, column, textEl) {
db.transaction(function(tx) {
tx.executeSql("UPDATE products SET ? = ? WHERE id = ?",
[column, textEl.innerHTML, id], null, onError);
});
}
Same with any full-bodied DBMS, you cannot parameterize the column names, only values.
So you need to do it like this
<span contenteditable="true"
onkeyup="updateRecord('+item['id']+', 'product', this)">'+ item['product'] + '</span>
function updateRecord(id, column, textEl) {
db.transaction(function(tx) {
tx.executeSql("UPDATE products SET " + column + " = ? WHERE id = ?",
[column, textEl.innerHTML, id], null, onError);
});
}