How to fill up my dropdown from my service? - ng-dropdown-multiselect

iam trying to fill up an ng-multiselect-dropdown From my clientservice , i can fetch my clients from database , but i don't know the correct syntax to send id and name to populate my list !
i have tried alot of examples with out any success ,was almost there,
What i tried so far :
this.dropdownList =
this.clientService.getClients().subscribe(
data => this.clients = data,
error => console.log(error),
() => this.isLoading = false
)};
here is my service file
getClients(): Observable<Client[]> {
return this.HttpClient.get<Client[]>('/api/clients');}
model :
export class Client {
_id?: string;
name?: string;
address?: string;
zipcode?: number;
city?: string;
email?: string;
phone?: string;
}
HTML :
<ng-multiselect-dropdown
[placeholder]="'custom placeholder'"
[data]="clients"
[selectedItems]=selectedItems;
[settings]="dropdownSettings"
(onSelect)="onItemSelect($event)"
(onSelectAll)="onSelectAll($event)"
>
</ng-multiselect-dropdown >
[Populated with [data]= clients[https://imgur.com/a/D1WFMlw]
am expecting a function to ( this.dropdownList = ) and populate my list from my service .so far i got aclients Objects list populated, i need to populate the client name and id :)
thank you all guys .

Related

Update a message "attributes" with a JSON for message type media

Since Flex is not supporting media messages im forced to do a workaround to store the file content in s3 bucket and update the media message with the link to s3.
Im using below code to update media message
http://localhost:8051/channel/CHe1XXXXXXXXXXXXXXXXX/messages/IMdb99326ebf7dXXXXXXXXXXXX
exports.updateMessage = async function (channelSID, messageSID, body) {
const messageObj = body;
const message = twilioClient.chat.services(variables.twilioServiceSID)
.channels(channelSID)
.messages(messageSID)
.update({
messageObj
})
.then(message => {
return message;
})
return message;
};
Request body:
{
"attributes":
{ "s3_url": "https://testingbucket.s3.us-east-2.amazonaws.com/fileupload" }
}
Response:
{"name":"test-adapter","hostname":"Abinaya","pid":14696,"level":30,"res":{"statusCode":200,"responseTime":1303,"headers":{"x-request-id":"4eb0077e-53e9-4965-9eb8-f0c314444d09","content-type":"application/json; charset=utf-8"}},"event":"response","body":{"status":"success","data":{"sid":"IMdb99326ebf7XXXXXXXXXXXXXX","attributes":"{}","to":"CHe16335c4a04643XXXXXXXXXXXXX","channelSid":"CHe16335c4a04XXXXXXXXXXXX","dateCreated":"2019-11-29T13:26:20.000Z","dateUpdated":"2019-12-02T09:31:58.000Z","lastUpdatedBy":"system","wasEdited":true,"from":"chintakindisantosh#gmail.com","body":null,"index":20,"type":"media","media":{"size":119238,"filename":"dominos.png","content_type":"image/png","sid":"MEb683c0cd51391f4bXXXXXXXXXX"}},"message":"Message updated successfully"},"msg":"request end","time":"2019-12-02T09:31:58.669Z","v":0}
Even after receiving 200 OK media message is not updated.
Resolution to the above issue.
The attribute is expected to be a string and inside we can give JSON.
interface ChannelListInstanceCreateOptions {
attributes?: string;
createdBy?: string;
dateCreated?: Date;
dateUpdated?: Date;
friendlyName?: string;
type?: ChannelChannelType;
uniqueName?: string;
}
So for example we can give something like below.
attributes : '{"clientName":"Test"}'

Electron Nedb findOne returns null?

I am calling a simple query with findOne, so far the data in users.db is:
{"id":40, "is_admin":1,"name":"John Smith"},
{"id":43, "is_admin":1,"name":"Laura Smith"}
// Users
var users = new Datastore({ filename: 'db/users.db' });
var id_user = 43;
console.log("-------------geting users db");
//
users.loadDatabase(function (err) {
console.log("------------- users db loaded--", id_user);
// find user by id
users.findOne({ id: id_user }, function (err, a,b,c) {
console.log(a,b,c); // displays null undefined undefined
});
});
Any idea why is returning null?
I think function being passed in findOne should take 2 parameters. First parameter will be the result of query and
second parameter will be error if something goes wrong . First parameter will be Null if there is no match in db .otherwise it should return the match result.
Function(result, error ){
}
It will be you function prototype
I tested your code in my app
db.findOne({ "c2cId":"292" }, function (err, a,b,c) {
console.log(a,b,c);
});
It return one doc and undefined, undefined.
If you use findOne I guess you just want to find the first doc, so looking at the
doc at
You can see there is only two parameters err and the doc
Concerning the null: in your query are you using a variable named id? or is it the key, in last case you should use quotes....

Unable to figure out how to use post method, for a suitescript written in Netsuite

I am trying to do use the post method for a simple suitescript program, i am very new to this.
In Netsuite i have written a suitescript as follows.
function restPost()
{
var i = nlapiLoadRecord('department', 115);
var memo = nlapisetfieldvalue('custrecord225', ' ');// this is a customfield, which i want to populate the memo field, using rest client in firefox
var recordId = nlapiSubmitRecord(i);
}
i have created a script record and uploaded this suitescript and even copied the external URL to paste it in restclient.
In Restclient(firefox plugin), pasted the external URL, i have given the method as post, header authorization given, content-type: application/json, and in body i put in {"memo":"mynamehere"};
In this the error i get is
message": "missing ) after argument list
I even tried it by writting other suitescript programs the errors i get is as follows:
Unexpected token in object literal (null$lib#3) Empty JSON string
Invalid data format. You should return TEXT.
I am kinda new to the programming world, so any help would be really good.
I think you are trying to create a RESTlet for POST method. Following is the sample code for POST method -
function createRecord(datain)
{
var err = new Object();
// Validate if mandatory record type is set in the request
if (!datain.recordtype)
{
err.status = "failed";
err.message= "missing recordtype";
return err;
}
var record = nlapiCreateRecord(datain.recordtype);
for (var fieldname in datain)
{
if (datain.hasOwnProperty(fieldname))
{
if (fieldname != 'recordtype' && fieldname != 'id')
{
var value = datain[fieldname];
if (value && typeof value != 'object') // ignore other type of parameters
{
record.setFieldValue(fieldname, value);
}
}
}
}
var recordId = nlapiSubmitRecord(record);
nlapiLogExecution('DEBUG','id='+recordId);
var nlobj = nlapiLoadRecord(datain.recordtype,recordId);
return nlobj;
}
So after deploying this RESTlet you can call this POST method by passing following sample JSON payload -
{"recordtype":"customer","entityid":"John Doe","companyname":"ABCTools Inc","subsidiary":"1","email":"jdoe#email.com"}
For Authorization you have to pass request headers as follows -
var headers = {
"Authorization": "NLAuth nlauth_account=" + cred.account + ", nlauth_email=" + cred.email +
", nlauth_signature= " + cred.password + ", nlauth_role=" + cred.role,
"Content-Type": "application/json"};
I can understand your requirement and the answer posted by Parsun & NetSuite-Expert is good. You can follow that code. That is a generic code that can accept any master record without child records. For Example Customer Without Contact or Addressbook.
I would like to suggest a small change in the code and i have given it in my solution.
Changes Below
var isExistRec = isExistingRecord(objDataIn);
var record = (isExistRec) ? nlapiLoadRecord(objDataIn.recordtype, objDataIn.internalid, {
recordmode: 'dynamic'
}) : nlapiCreateRecord(objDataIn.recordtype);
//Check for Record is Existing in Netsuite or Not using a custom function
function isExistingRecord(objDataIn) {
if (objDataIn.internalid != null && objDataIn.internalid != '' && objDataIn.internalid.trim().length > 0)
return true;
else
return false;
}
So whenever you pass JSON data to the REStlet, keep in mind you have
to pass the internalid, recordtype as mandatory values.
Thanks
Frederick
I believe you will want to return something from your function. An empty object should do fine, or something like {success : true}.
Welcome to Netsuite Suitescripting #Vin :)
I strongly recommend to go through SuiteScript API Overview & SuiteScript API - Alphabetized Index in NS help Center, which is the only and most obvious place to learn the basics of Suitescripting.
nlapiLoadRecord(type, id, initializeValues)
Loads an existing record from the system and returns an nlobjRecord object containing all the field data for that record. You can then extract the desired information from the loaded record using the methods available on the returned record object. This API is a core API. It is available in both client and server contexts.
function restPost(dataIn) {
var record = nlapiLoadRecord('department', 115); // returns nlobjRecord
record.setFieldValue('custrecord225', dataIn.memo); // set the value in custom field
var recordId = nlapiSubmitRecord(record);
return recordId;
}

echo posted json data in server php

The json sent to server php file as post request from ibm worklight Http adapter not accessible even after decoding:
Here are the codes:
Http adapter:
function storeRegistrationData(emailVal, passVal, fname1, gender, phone, userType, vehType) {
var credentials = JSON.stringify({jemailVal: emailVal, jpassVal: passVal, jfname1: fname1, jgender: gender, jphone: phone, juserType : userType, jvehType : vehType});
var input = {
method : 'post',
returnedContentType : 'json',
path : "/carbikepooling/index.php",
parameters: {credentials: credentials}
};
return WL.Server.invokeHttp(input);
}
Server php code:
$jsonObj = (isset($_POST['credentials']) ? $_POST['credentials'] : null);
$credentials = json_decode($jsonObj);
$email = $credentials->jemailVal;
$pass = $credentials->jpassVal;
$uname = $credentials->jfname1;
$gender = $credentials->jgender;
$phone = $credentials->jphone;
$usertype = $credentials->juserType;
$vehtype = $credentials->jvehType;
$boolean = false;
$userId; $userTypeId;
// sanitation, database calls, etc
$connection = mysqli_connect("localhost","root","","carbikepooling");
if (mysqli_connect_errno($connection))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($connection,"insert into userInfo values(0,".$email.",'".$pass."','".$uname."','".$gender."','".$phone."')");
$result1 = mysqli_query($connection, "select u.userId from userInfo u order by u.userId desc limit 1");
if($result1){
$row1 = mysqli_fetch_row($result1);
$userId = $row1[0];
mysqli_query($connection,"insert into userType values(0,".$userId.",'".$usertype."')");
$result2 = mysqli_query($connection, "select t.userTypeId from userType t order by t.userTypeId desc limit 1");
if($result2){
$row2 = mysqli_fetch_row($result2);
$userTypeId = $row2[0];
mysqli_query($connection, "insert into vehicleType values(0,".$userTypeId.",'".$vehtype."')");
$boolean = true;
}
}
mysqli_close($connection);
$returnData[] = array(
'boolean' => "$boolean"
);
echo json_encode($returnData);
?>
Javascript code to show return result from server php:
function storeFormData(emailVal, passVal, fname1, gender, phone, userType, vehType){
var invocationData = {
adapter : 'registerUser',
procedure : 'storeRegistrationData',
parameters : [emailVal, passVal, fname1, gender, phone, userType, vehType]
};
WL.Client.invokeProcedure(invocationData, {
onSuccess : storeFormDataSuccess,
onFailure : storeFormDataFailure,
});
}
function storeFormDataSuccess(result){
WL.Logger.debug('Data stored Successfully');
alert(JSON.stringify(result.invocationResult));
}
function storeFormDataFailure(result){
WL.Logger.error('Error in storing Data');
}
What happens is that when I used decoded json data in server php file in the insert statements, nothing happens. I tried echoed values of email, gender, etc. but nothing prints as if they contain no values. However, if I sent the decoded json values of email, gender etc. in the returnData array as they are used in insert statements, values successfully received by the app which made the request, i.e: shown those values in the alert in the js code. Please solve this problem?
Hmm, that is strange. I copied and pasted your exact code and I was able to echo the variables that were passed from the Worklight adapter. Maybe the way you are trying to use the variables for your sql statements is wrong?
Can you change your mysql query to look something more like this?
mysqli_query($connection, "insert into vehicleType values(0, '$userTypeId','$vehtype')");
Notice how I've removed the concatenation '.' from the query and I now I just have the variables surrounded by single quotes.

Backbone toJson doesn't return attributes when id is a string

I am running some rails code to generate json to be consumed by backbone. When I treat the id like a string, and consume it in backbone, the toJSON() function doesn't return the attributes. When I call a to_i on the id, toJSON() works properly. (But this breaks my app because "012345" is different from 12345.
My backbone view:
serialize: ->
console.log #model.toJSON()
info: #model.toJSON().info
non-working json response:
{"id":"123456","info":[{"label":"Hire Date","text":"06-NOV-00"},{"label":"User ID","text":"YADDA"},{"label":"Employee Number","text":"123456"}] }
non-working toJSON result:
data_partition: DataPartition
id: "123456"
__proto__: Object
working json:
{"id":123456,"info":[{"label":"Hire Date","text":"06-NOV-00"},{"label":"User ID","text":"YADDA"},{"label":"Employee Number","text":123456}] }
working toJSON():
data_partition: DataPartition
id: 123456
info: Array[3]
__proto__: Object
But this breaks my rails app when I chop off leading 0's.
Running this code I don't find any issue:
var responseJSON_1 = {"id":"123456","info":[{"label":"Hire Date","text":"06-NOV-00"},{"label":"User ID","text":"YADDA"},{"label":"Employee Number","text":"123456"}] };
var responseJSON_2 = {"id":123456,"info":[{"label":"Hire Date","text":"06-NOV-00"},{"label":"User ID","text":"YADDA"},{"label":"Employee Number","text":"123456"}] };
var MyModel = Backbone.Model.extend({});
var myModel_1 = new MyModel( responseJSON_1 );
var myModel_2 = new MyModel( responseJSON_2 );
console.log( myModel_1.toJSON() );
console.log( myModel_2.toJSON() );​
Check the working jsFiddle
Are you sure you are not changing more things in your response than the id format?

Resources