NetSuite Record Creation Event - netsuite

How can I change a field on a form when it is initially created, but not when it is later edited? I'm currently using a Client script and coding for this with the pageInit function, but I need to allow my users to manually change the field after it is initially created without the script overriding their changes.
Let me know if more details are needed for what I am exactly trying to accomplish.

As I mentioned in a comment above, I figured this out. Using the type parameter of the pageInit function, I can make events fire on page edit or page creation like this:
function pageInit(type){if(type == 'create'){//do stuff}else{//do other stuff}}

Related

ModifiedBy field in SharePoint Document library is always my name instead of the one who triggered the flow

I have a flow, that gets triggered when a file is created in the Documents. The flow will add a column to the document library. The problem is that the modified by field in the Document library always contains the value as my name, instead of showing the user who triggered the flow.
I have already followed this article and seems like that is not working on my end.
After doing those changes, my flow runs fine without any error and giving an output as proceeding.
{
  "d": {
    "ValidateUpdateListItem": {
      "__metadata": {
        "type": "Collection(SP.ListItemFormUpdateValue)"
      },
      "results": [
        {
          "ErrorMessage": null,
          "FieldName": "Editor",
          "FieldValue": "[{\"Key\":\"i:0#.f|membership|nk#fdgfsgfs.de\"}]",
          "HasException": false,
          "ItemId": 1
        }
      ]
    }
  }
}
But there are no changes in the Document library, it still shows my name in the modified by column as I created the Flow. Even if this worked, I have another question that how can I dynamically find out and add who is triggering the Fow instead of giving a static editor claim in the first Compose step in the above image?
Anyone else faced this issue? Any help is really appreciated.
I do not think it is possible at the moment to dynamically find the current logged in user. you can check out this post
https://powerusers.microsoft.com/t5/Building-Flows/Flow-to-SharePoint-list-item-change-quot-Created-By-quot/td-p/93668
I could solve this issue by using the REST API in the flow itself. This is what I did,
Get the user who called the flow
Update the Modify field by using the REST API in the flow itself
This blog post will help.

Task field that links to the originating transaction

I have a custom task form that has a field which displays the transaction id (in this case a sales order)for the record the task was created in.
I would like to have this field be a hyperlink to that specific transaction but am lost on how to do this.
Is this possible?
In view mode on the task any records linked under the 'related records' tab are links to the respective record. This is automatic.
If you want on the main section you can add one with a user event script possibly coupled with a client event script.
In the Before Load user event script detect that a transaction is assigned and create a new field of type URL and use the N/url module to derive the url of the transaction.
If the user who needs the link is allowed to change the linked transaction then you could also add a client script that uses a fieldChanged event to update the value of the custom field added in the User Event script.
If you need the client script and want to eliminated duplicate code then you could set the value of the url custom field in the pageInit event of the client script (i.e. both the pageInit and fieldChanged events could use the same url resolution code.
The field must be of type List/Record pointing to a Transaction list, or an HTML type set using an <a href="url"> attribute.
I would advise against hard-coding links in the system though, and try to use the List/Record field type first.
Hope that helps! If not, feel free to comment back and I'll see what other help I can provide. If possible, please provide screenshots.

Display a user friendly message in user event script

I'm trying to do some validations using a user event script but I want to show user some meaningful error instead of the default 'suitescript' error at the end. Is there any way to do this?
User Events are server-side, so there is no UI in which to display a message. You cannot validate date on beforeSubmit and display a message. If you want to validate as the user saves and show them feedback, you need to use the saveRecord entry point on a Client Script.
You can do this via the beforeLoad entry point because it receives a reference to the Form in context, which has an addPageInitMessage entry. Check out the Help docs for this method to see if it will work for your case.
As #erictgrubaugh suggested you cannot use User Event for validation.
If you want to perform validation and stop form submission, you need to use ClientScript with saveRecord and you can perform all of your validations here. If current record does not passes your validation you show user error using N/ui/message with some description and if everything is correct return true.
To stop current record from being saved, return false from saveRecord.
Check this out to see how to use N/ui/message and this for further reading on saveRecord.
You can use "throw" to display error message on before submit.

Script Type(s) for Updating All Item Records in NetSuite

I'm still new to NetSuite, so I appreciate any help you all can provide. I've created a script to update a couple custom fields on item records. Currently, it is a Client script, and while I do want it to execute when a user updates a record, I'd also like it to execute after a server update as well. In addition, I'd like to apply this to all current item records to provide a baseline for future changes.
Have I made this overly complicated? What script type should I be using? Can I get this done with one script, or do I need multiples? Thank you for the help!
You should use one User Event script that would run whenever a record is updated. you can deploy the script to run on items. In the user event you can check for context (e.g.: user interface, particular script type, maxss update etc.) if you do not want to run it in all context

How to automatically print a form when a new item is posted to a list in SharePoint?

How to automatically print a form when a new item is posted to a list in SharePoint?
I created a list in SP, with customized Entry and Edit forms and a workflow that connects them. Every time a new item is posted the Entry form needs to be used, but when I click submit I need the workflow not only to post the item to the list, but also generate a 'Print form' that can either saved or printed.
Considering the event, adding an item triggers an SPItemEventReceiver.ItemAdded. You would call your printing code from within this event, and deploy the functionality through a Feature.
To give a really specific answer, you'll need to explain a bit more - where should the printing occur? On the machine from which the list was modified, or some central printing location?
More generally, Sharepoint can trigger a variety of events. Ishai Sagi's blog has a user-triggered solution that may give you some ideas. You could use a Javascript event as explained here. You could even send a specially-formatted email to a computer with Outlook running, with a rule that triggers a print.

Resources