Change default PO form for a role based on condition - netsuite

I have a requirement where I need to default certain fields on the PO form if the particular PO is created from MRP. I have created a summary field which will result data if the PO is created from a planned order. Now I need to default certain fields only for a role in this case. I was thinking of creating another custom form and defaulting all the fields using a workflow and call it only when the summary field has a value. The defaulting should not happen in other cases.
Please advice on the best approach on this, I am not much proficient in scripting yet.
Thanks

You can do this either via script or workflow,In case of a workflow default the values of the fields with the condition of your summary field and the role.If you want to do it in script something like this will help you
var userObj = runtime.getCurrentUser();
log.debug("Internal ID of current user role: " + userObj.role);
var userObj = runtime.getCurrentUser();
log.debug("Custom script ID of current user role: " + userObj.roleId);

Related

Workaround to search Netsuite Note record by Customer id

I'm trying to get an app I'm working on to display all associated user notes for a given Customer record (as it appears on the UI Customer record page in Netsuite proper).
To that end, I've set up a Netsuite RESTlet to return a list of internal ids for associated Note records given a Customer internal id.
I've set up a simple search in the RESTlet script:
function get_notes(params) {
log("GET params", JSON.stringify(params));
var filters = [
new nlobjSearchFilter('internalid', 'customer', 'is', params.id)
];
var columns = [
new nlobjSearchColumn('internalid'),
new nlobjSearchColumn('note'),
];
var search = nlapiCreateSearch('note', filters, columns);
var notes = search.runSearch().getResults(0, 3);
return notes;
}
function log(msg, details) {
nlapiLogExecution('DEBUG', msg, details);
}
The script works as expected, but the problem is that this search ONLY returns Notes for which the author field (which is a user internal id) matches the internal id of the user performing the search. Meaning - you can only search for Notes for which you are the author.
I have been informed that this is a 'feature' of Netsuite for some unfathomable security reason.
I need to be able to get a list of all the associated Note ids, not just those for which the user making the request is the author.
Any ideas on a workaround to get at all the associated Notes? A different way to structure the search? Some kind of secret way to define your own custom Search Joins?
I can't even find documentation on this behavior (blocking Note searches from non-authors). Perhaps someone knows how to override it at the admin level?
I'm not quite ready to admit that this is impossible yet.
NB: User Note is a Note-type record associated with the Customer record, not a field on Customer record, so I can't access it directly from Customer. There is also not a Search Filter or Search Join for Note or User Note.
Using RESTlets you cannot get the notes of other users unless you invoke the RESTlet using credentials/tokens of roles like Administrator/Full Access. RESTlets always runs in the context of current user.
One alternative to do that, if you really got to achieve this any how:
1) Create a user event script on customer which creates a custom record that simulates the functionality of system notes.
2) Make sure that the RESTlet user roles have full level of access on the custom record and make customer as parent of your custom record.
3) In your RESTlet return the custom records.
Basically RESTLETS always run as the user who invokes them.
If you can use a Suitelet for this you can set that up to run as Administrator and can return any Notes you can craft a search for.
Are you actually needing a Restlet ? i.e. Are you calling this from an external application or are you trying to add functionality in the NS GUI? If the latter then you can easily use a Suitelet.

Lotus notes, edit one form from another

Basically what I want to do is create a form whilst within another form and pass values from the earlier form to the second. Complicated I know but here is what I got.
#Do(#Command([Compose];"LPK"); #SetField("PR_Make"; PR_Make))
The fields in both forms have the same name and this code is called when first document is attempted to be saved.
I think instead of editing the field on the second form it just saves a field as itself instead. Any help appreciated.
The best and common way is to enable form property "Formulas inherit values from selected document" in second form "LPK".
Add a default value formula to second form's fields you want to inherit and put just the name of field itself in. For your example default value formula it would be
PR_Make
Make sure you save document first and then create the new document.
Knut Hermann's answwer is the 'standard' way of achieving such things but there are other methods- eg you can use environment variables ..
Something like:
#Environment("PR_Make") := PR_Make;
#Command([Compose];"LPK");
Then set the default value for PR_Make in your new form as ..
#Environment("PR_Make")
FYI Environment variables are written to the user's Notes.ini file and so remain even after Notes has been closed and re-opened. #Environemt doens't work too well with Web applications as it uses the server's notes.ini.
An alternative would be to use profile documents:
#SetProfileField( "PRDefaults"; "PR_Make" ; PR_Make;#Username);
#Command([Compose];"LPK");
.. in the default field for PR_Make on new form :
#GetProfileField( "PRDefaults"; "PR_Make"; #Username);
Profile documents are stored as a kind of hidden document in the Notes database and persist with the database. The last parameter sets a further subdivision by username so each user gets their own profile doc - a bit like a personal profile for "PRDefaults". You can miss this last parameter #Username out, to have one profile doc per database but there's a risk of two people trying to use it at the same time and clashing.
Profile docs also work with web applications.

NetSuite nlapiSubmitField for a List/Record

I am having trouble with a RESTlet I am working on. I am bringing in a list of individuals who are canceling their service. I need to then go through the list, set their accounts to cancelled, and give a reason why it is cancelled in symptom field called "custrecord_scrapsymptomcode". The symptom field is of type "List/Record" and refers to one of the 20 items in a list called "Symptoms".
I am able to iterate through the individuals and set multiple fields on their record, however I am not able to set the value of the "Symptoms" field, which is supposed to be one of the values from the list. When I attempt to do so I receive an error that "that record is not editable".
I have tried the following strategies so far with no luck:
nlapiSubmitField('customrecord_customer', j, 'custrecord_scrapsymptomcode', s);
and
var rec = nlapiLoadRecord('customrecord_customer', j);
nlapiSetFieldValue('custrecord_scrapsymptomcode', s);
nlapiSubmitRecord(rec);
'customrecord_customer' is the ID of the record type I am attempting to change
'j' is the internal ID of the customer record I am attempting to edit
'custrecord_scrapsymptomcode' is the ID of the field that I am attempting to set
's' is the symptom or reason for cancellation. It should be an item from the list of symptoms. I am not exactly sure why but it seems to only want an integer value.
Is there a better way to set this field value given that it is an item of a list? Is the error I am receiving related to the way I am scripting the record or it this more of a configuration/permissions issue with my system? I should have full admin rights on my system if that is helpful.
Thanks!
Try this :
var rec = nlapiLoadRecord('customrecord_customer', j);
rec.setFieldValue('custrecord_scrapsymptomcode', s);
nlapiSubmitRecord(rec);
nlapiSetFieldValue('custrecord_scrapsymptomcode', s);
This will not work in a restlet - there is no 'current record'.
rec.setFieldValue('custrecord_scrapsymptomcode', s)
will set the value on the record you have just loaded.
As for your error - that might be a permissions error - check the role that the restlet is executing as, and check the default form for that role, and make sure that this particular custom record is editable by that role.
The custom field ids are prefixed with custentity. Please make sure that you are using the correct internalId of the field.

CRM 2011 - Form onload, transfer field data to entity

I've set up contacts in leads successfully but when a user adds a new contact it wont auto fill in the parent lead field i created to link the contact to the lead.
Does anyone one know what script i could use onload that will auto fill a filed on the lead called Parent Lead. It needs to update the contact field with the leads primary account.
Hope that makes sense.
At the moment the user has to find the lead through the custom lookup field.
Check your relationship ... 1to1, 1tomany, manytomany?
here is the code to populate a lookup field anyway:
var value = new Array();
value[0] = new Object();
value[0].id = idValue;
value[0].name = textValue;
value[0].entityType = typeValue;
Xrm.Page.getAttribute("fieldName").setValue(value);

Creating a view of users who have created nodes

Basically i want to creeate a block diaplay view,which displays a list of all the users thata have posted some nodes on the drupal website.
Oddly enough thinking about this right now it could be a little tricky. You have two possible solutions off the top of my head.
1 - Create a new view of item type Node. Your row style will obviously be set to Fields. Under which Fields to pull select the User group and then tick off the User: Name checkbox. Set your Items to display setting to 0 for unlimited results.
Under the preview you should get a ton of results looking something like:
Name: John Doe
Name: Mary Jane
Name: John Doe
Name: Anonymous
What you're seeing is the authors of all the nodes posted in your system. There will be duplication because a user in your system could be the author of multiple nodes. Unfortunately you can't just tick off the Distinct: Yes option because this only applies to nodes and not the users.
How to deal with the duplicate user name results tho? Custom theme your view by creating a custom template under Theme: information. Inside the template write some PHP code which intercepts the row results from the View query before it renders and only render distinct user names from the results. You'd have to write the logic though to determine whether a user name has already been added.
As simple as creating a new custom array, adding each row result (user name) to array but first checking to see whether it already exists in your custom array - if it does then toss it and move on to the next user name. At the end you'll have an array filled with distinct user names who have posted on your site.
voila! It works. It's not elegant but it definitely will work if built this way.
2 - Alternatively maybe you can get this module working to accomplish the same thing in a less complicated manner: http://drupal.org/project/views_customfield but I have never used it so I cannot comment on it.
Good luck. Hope that helps.
My solution was to:
Create a view of people
Add a UID field (and any other fields you want)
Create a theme.tpl.php file for the Row Style
Do a DB call on each loop through the row to search for nodes created by the supplied UID.
Here is what I have in my semanticviews-view-fields-VIEWNAME.tpl.php
<?php
//Query the Drupal DB for nodes associated to the supplied UID
$existing_nid = db_query("SELECT nid FROM {node} WHERE (type = :ctype) AND uid = :uid", array("ctype" => "CONTENT_TYPE", "uid" => $fields['uid']->content))->fetchField();
//If the supplied UID created content of the supplied type, then show their name
if ($existing_nid != FALSE) {
echo "Name:" . $fields['name']->content;
}
?>
This way only UID's that have content associated to it in the DB will be printed out, and those that don't, won't.
Hope that helps!

Resources