Adding Drop Ship PO to Existing Sales Order in NetSuite - javascript

I'm needing to create drop ship purchase orders against sales orders within NetSuite that already exist and have one or more drop ship POs created against it. Now, normally through the UI you can just click the "Drop Ship" link on an item line and there you go, but this is being done programmatically with SuiteScript. I thought I had this figured out years ago, but it was years ago, this hasn't come up since, and I can no longer remember what files I may have been working on at the time.
The system won't allow reverting the order to a "Pending Approval" status, so I can't just change statuses around to force the system to create the new POs. I've also tried the following to no success:
soRecord.setCurrentLineItemValue("item", "createpo", "DropShip");
soRecord.setCurrentLineItemValue("item", "povendor", vendorId);
Nothing happens aside from adding the new item lines to the sales order. I've also tried creating a PO with the appropriaate vendor and attaching it to the item line on the sales order with the following, but it also has no effect:
soRecord.setCurrentLineItemValue("item", "createdpo", poId);
Is there something I'm missing? Or have I been embarking on a fool's errand the entire time?

Those fields are read only. This is what I used
var po = nlapiCreateRecord('purchaseorder', {recordmode:"dynamic", soid:<internal id of salesorder>,poentity:<preferred vendor of item>});

We had an issue where our auto-drop ship POs stopped generating on SO creation. In an afterSubmit UE deployed to SOs, gather an array of vendors on the item lines and then filter to remove duplicates. Then add this logic inside of a for-loop where i < length of filtered vendor array:
var createDSPO = record.create({
type: record.Type.PURCHASE_ORDER,
defaultValues: {
soid: <SO internal id>,
shipgroup: 1,
dropship: true,
custid: <SO customer internal ID>,
entity: poVendorArray[i],
poentity: poVendorArray[i]
}
});
createDSPO.save();
FYI, if you inspect the "Drop Ship" link on the SO record, you'll see why I did this. You may be able to figure out another way to do this.

Related

Apex Trigger: Use a trigger to update a custom field with data from another object

I am attempting to write a trigger and I relatively new to both Salesforce and Object oriented programming and I am struggling, so any help would be appreciated!
Task Description:
I have two custom objects, Employee, and Position Associate. Position Associate is an object that creates a mapping and record between an employee and a respective position that they hold. I am attempting to write a trigger, that runs any time a Position Associate is created or updated, that takes three fields, Training Start, Training End, and Home Study Start, and populates it with data from the employee object, from the employee that is mapped to the Position Associate record in question. This must be a trigger as opposed to a making the field a lookup value. So while that may be simpler, it is not an option in this scenario
Current Behavior: While I am not getting any errors, after a record is updated, the fields still remain blank.
Code:
trigger MapDatesPA on Position_Employee__c (after insert,after update)
// Create trigger that runs when a new record is inserted or when a record is updated that maps the employee fields //of Home Study Start Date, Training Start and End Dates to Position Assoicate Object
{
//Prevent Iterative Loop
if(checkRecursive.runOnce()){
Map<Id,Employee__c> pm = new Map <Id,_Employee__c>();
Set<Id> empIds = new Set<Id>();
for(Position_Employee__c posEmp: Trigger.new){
if(posEmp.Employee__c != null){
empIds.add(posEmp.Employee__c);
}
}
for(Employee__c emp:[Select Id, HOME_STUDY_START_DATE__c,Training_Start_Date__c,Training_End_Date__c From Employee__c Where Id In :empIds]){
if(pm.containsKey(emp.Id)){
pm.put(emp.id, emp);
}
}
for(Position_Employee__c posemp: Trigger.New){
If(pm.containsKey(posemp.Id)){
posemp.Training_Start_Date__c = pm.get(posemp.Id).Training_Start_Date__c;
posemp.Training_End_Date__c=pm.get(posemp.Id).Training_End_Date__c;
posemp.Home_Study_Start_Date__c=pm.get(posemp.Id).HOME_STUDY_START_DATE__c;}
}
}
}
I believe the issues lies in the last section but I am completely lost as to why and what the error is as the debugger isnt logging anything. I greatly appreciate any help!

Use user input from previous trial as stimulus in a new trial

I'm trying to program an experiment with the JavaScript package JSPsych. The MWE of my experiment is supposed to do the following: The participant enters a letter in a survey-text trial and in the following html-response trial, this letter is supposed to be presented to the participant as a stimulus.
My problem is that I can't find a way to access the input of the participant in the survey-text trial. My program structure follows the reaction time tutorial on the JSPsych website: The trials are being created one after another and pushed into a timeline array which is being initiated at the very end of the code. What that means is that at the time the trial is being defined the user has not input anything yet.
My MLE code can be found below. While running the experiment in a browser I am able to access the data from the survey-text trial with JSON.parse(jsPsych.data.getLastTrialData().select('responses').values).favorite. However, in the code below this produces the following error: SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data, because (I strongly presume) there is no last trial at the time the code is being compiled.
let letter_display, letter_survey, test_procedure, timeline;
timeline = [];
letter_survey = {
type: "survey-text",
questions: [
{prompt: "What is your favorite letter?", name:"favorite"}
],
}
timeline.push(letter_survey);
letter_display = {
type: 'html-keyboard-response',
stimulus: jsPsych.timelineVariable('stimulus'),
};
test_procedure = {
timeline: [letter_display],
timeline_variables: [{type:'html-keyboard-response', stimulus: JSON.parse(jsPsych.data.getLastTrialData().select('responses').values).favorite}]
};
timeline.push(test_procedure);
jsPsych.init({
timeline: timeline
})
I have found a solution. The part of the code where a value is assigned to the letter_display variable has to be changed as follows:
letter_display = {
type: 'html-keyboard-response',
stimulus: JSON.parse(jsPsych.data.getLastTrialData().select('responses').values).favorite
};
timeline.push(letter_display);
All code relating to the test_procedure variable can be scraped.
I.e. I got this to work for a "flat" timeline, but not a nested one. If anyone has a nested timeline solution, I would appreciate if they posted it as an answer here.
As a side note: Using JSON.parse(jsPsych.data.get().filter( {trial_type: 'survey-text'} ).select('responses').values).favorite generalizes to cases where the user input is not from the last trial.
Let me add another way
The on_start of the trial also works! It can change the stimulus or anything parameters of the trial based on the last trial's repsonse.
letter_display = {
type: 'html-keyboard-response',
stimulus:''
on_start:function(trial){
trial.stimulus =jsPsych.data.getLastTrialData().select('responses').values.favorite
}
};
timeline.push(letter_display);
(if you do not assign the stimulus before the on_start, it can work, but with error message in console)

Firebase convert generated ID to numeric ID

This is an old question but no answers found. Old answers' source links are dead, old functions are deprecated.
I've look at these topics (1, 2) amongst others, and also current Firebase guide.
function writeUserData(name, win, loss) {
firebase.database().ref('users/').push({
name: name,
wins: win,
losses: loss
});
}
I need to pull or somehow convert the unique ID from each push to numeric ID: 1, 2
UPDATE:
Here's what I'm trying to do:
2 users can login at the same time from 2 different browsers.
1st user hits button 'log-in' or 'start' will be written as users/1/{user's attributes} on firebase.
if there's an existing user
(somehow I need to check that on the user-end), the next user hits
'start' will be written as users/2/{user's attributes} on firebase. Else (no existing user), the user will be written as user1. This is where I think I need push instead of set. I can use set to add more users from 1 browser, but if i open the app from another browser/chrome incognito, the app will just reset the existing users.
if a user refreshes or closes the browser, that user will be removed from firebase so another user can log-in.
I've tried different methods (loop, creating new var...) to achieve this.
Rather than .push, try to use .set or .update. In that way you can set your own generated key. But as already suggested, this may not be the best approach.

How can I make Qooxdoo virtual list scalable?

I need to show list of data , at least 1 million rows (Big data , machine learning).
I do not need to show at once , remotetablemodel of qooxdoo table works fine but instead of table i choose list as design choice.
Below is a test i've made.
//create the model data, 1mil items
var rawData = [];
for (var i = 0; i < 1000000; i++) {
rawData[i] = "Item No " + i;
}
var model = new qx.data.Array(rawData);
//create the list
var list = new qx.ui.list.List(model);
this.getRoot().add(list);
I understand the point that it will take long to generate rawdata and assign it to list.
But the problem is after assigning the list , the virtual list itself is almost non-responsive.
Scrolling is very slow , navigating by down arrow freezes a few secs too.
Qooxdoo virtual infrastructure is suppose to render only visible items if i understand correctly? But in above test case it is so slow.
I expect to work like remote table model .
Tested with qooxdoo latest 4.0.0 and 3.5.1 , on Chrome 35 stable.
I can reproduce you issue only with the source version and not with the build version. I found the reason why the performance is so slow. There is an runtime check in an internal method from the SingleValueBinding which has a huge performance impact on the rendering.
I opened a bug report for that:
http://bugzilla.qooxdoo.org/show_bug.cgi?id=8439
But as I sad this issue only occurs with your developer version. So your customers are not effected.
You can disable the check if you want. Just remove the check block:
https://github.com/qooxdoo/qooxdoo/blob/master/framework/source/class/qx/data/SingleValueBinding.js#L915
You can also load your model data in parts to improve the model creation. You can maybe load the next part when the user has scrolled to the end of the list. You can use the example you have already seen:
Infinite scroll in qooxdoo with virtual list

Exporting Popcorn.js TrackedEvents to jSON

I'm build a VideoAnnotationEditor with Popcorn.js. Users can click on the video when they want to post a comment(=footnote) and enter text and duration. I'm adding footnotes like this:
p = pop.footnote({
start: 0,
end: duration,
text: text,
target: "footnotediv"
});
When all footnotes are added I want to store the data to a database. But how can I get all footnotes in a nice format? I tried
JSON.stringify(pop.getTrackEvents())
but it contains a lot und unnecessary stuff. Is there another way or should I store all footnotes in an own data-structure before adding them to popcorn.
Thx for any help.
Unfortunately, Popcorn isn't going to do this for you, since it stores it's "private" data on the same object as plugin-specific, user-specified data. Each one of those track event objects will have a bunch of private stuff (_natives, compose, _running, etc) and sometimes semi-private stuff that can be added by the plugin (e.g. container).
If you want to filter these out yourself, you can either blacklist the fields you don't want to save or you can whitelist the fields you do. If you have a lot of different plugins, and you don't always know what fields you're going to need, go with the blacklist. But honestly, having done that a few times, I advise just storying your own data structure outside of Popcorn.
But if all you're doing is footnotes, that's relatively simple, and the whitelist approach should work. Like so:
var trackEvents = pop.getTrackEvents();
trackEvents = trackEvents.map(function (trackEvent) {
return {
start: trackEvent.start,
end: trackEvent.end,
text: trackEvent.text
};
});
saveData(JSON.stringify(trackEvents));

Categories