How to get the value of a Business Central Page field based on a global variable - saas

In the Demand Forecast page 99000919, all of the "Header" data fields are backed by global variables. I need to default the View by Period (PeriodType) to Month and then validate the value. I have not been successful at doing so.
A. Using Modify(PeriodType) to get the value from the OnAfterValidate trigger. PeriodType shows up in intellisense when I use the Modify, but when I try to use it, I get a compiler error that PeriodType does not exist in the current context.
modify(PeriodType)
{
trigger OnAfterValidate()
begin
MyPeriodType := PeriodType;
end;
}
B. I also tried to use the VS Code teventsub code snippet to subscribe to the OnAfterValidate event for PeriodType, but there is nothing exposed.
[EventSubscriber(ObjectType::Page, Page::"Demand Forecast", 'OnBeforeValidateEvent', 'PeriodType', true, true)]
Can this be done in the SaaS solution with extensions? Any ideas or suggestions are welcomed.

At the moment there does not appear to be any events for you to subscribe to, that would help you solve the problem.
The first thing to do then is to submit a request to Microsoft to add the needed events to the product. Request New Events
That being said there is a workaround for your problem, which involves a few steps:
Create a copy of Demand Forecast (Page 99000919).
Code your required changes in your copy of the page
Substitute the original page with your copy
The last step is achieved by identifying all places where the original page is opened and then overtaking the code.
There are three places where Demand Forecast is opened:
Page 99000921, Demand Forecast Names, Action Edit Demand Forecast
Page 8907, Sales & Marketing Manager RC, Action Forecast
Codeunit 5530, Calc. Item Availability
1 and 2 are run non-modal which means in both cases you can do the following:
[EventSubscriber(ObjectType::Page, Page::"Demand Forecast Names", 'OnBeforeActionEvent', 'Edit Demand Forecast', true, true)]
local procedure Page_DemandForecastNames_OnBeforeActionEvent_EditDemandForecast(var Rec: Record "Production Forecast Name")
var
DemandForecastCopy: Page "Demand Forecast"; // this variable should reference your copy
begin
DemandForecastCopy.SetProductionForecastName(Rec.Name);
DemandForecastCopy.Run();
Error(''); // this creates a silent error which cancels the original execution of the action.
end;
SetProductionForecastName should not be called for "Sales & Marketing Manager RC".
The third one is a bit trickier because the page is run modal from the codeunit, but since we have now replaced all occurrences where the page is run non-modal, we can now assume that every time the original Demand Forecast is opened it should be modal.
Unfortunately subscribing to the Demand Forecast OnOpenPageEvent won't help you because there are no parameters to get values from. So you have to backtrack the code from Calc. Item Availability to find all possible entry points and then override the default implementation as described earlier.

Related

How do I get the event tags for a Coverity issue?

If I am looking at an issue in the Coverity user interface, how do I get the event tag or tags? I need to know a tag in order to suppress the finding using code annotations, as described in the question "How can I disable coverity checking using code annotation?" but I'm not seeing it or maybe don't know where to look.
The event tag is the first identifier-like word in each line of commentary that makes up the issue report.
For example, on Github, RcppCore/Rcpp issue 760 contains a screenshot that I have reproduced at half-size resolution with some annotations:
Zooming in on the code panel:
There are three events here:
alloc_fn: Storage is returned from allocation function operator new.
noescape: Resource new Rcpp::Rostream<true>::Buffer is not freed or pointed-to in basic_ostream. ...
leaked_storage: Failing to save or free storage allocated by new Rcpp::Rostream<true>::Buffer leaks it.
The event tags are "alloc_fn", "noescape", and "leaked_storage".
In this instance, all of them are associated with the same line of code (line 49), but in general they may appear on different lines and spread across multiple files.
To navigate to all of the events, use the Occurrences panel:
The Occurrences panel shows all of the events, organized into a tree, where child nodes are events in callee functions. The entire list is generally ordered in program execution order, although some events may be chronologically disconnected, for example if the finding involves multiple execution paths.
Each entry in the Occurrences panel has an event number (again, nominally chronological), the event tag, and the file name and line number. Clicking on an entry navigates to that event in the code panel.
Here are a couple related Synopsys support articles:
how to add code annotation? I do not know which name should exist with //coverity[]
Is there a document that lists all defect 'events' with their name and descriptions?

Why does the Google Tag Manager automaticalls has a Trigger event for gtm.load for my custom variables?

So I want to Trigger my Tags when the user accept cookies, obviously.
I tried different approaches, JSVariable, Custom JS, First party cookie and datalayer variable.
Now I have them all set in Triggers, for example if the JSVariable is true or if the first party cookie contains the cookie value I set, or the datalayer variable contains filled.
Now in Debug mode these Triggers actually seem to work. They all get Ticks under firing triggers, but the Tags don't seem to Trigger because I get another Trigger for some reason which states
gtm.load equals [variableName] (for example: gtm.load equals myJSVariable) and it always has this red X.
I just don't seem to find an answer to this problem.
Thank you all very much
So if anyone experienceses something similar (in case I am not the only dummy):
When you type in the eventname, it is about WHEN to look for your variable basically.
So for example you would enter gtm.load, when the site has been completely loaded. Then GTM would look for your CustomVariable

Automatically send email about editing google spreadsheet

I'm working on a rather simple script which should handle new values in the spreadsheet and then send emails to specified addresses. And I faced with the problem. My code is listed below:
function onEdit(e) {
//part of the code for checking e.range to process only updated values
sendEmail();
}
function sendEmail() {
// arguments are missed only for demo
GmailApp.sendEmail();
}
While I'm using "simple trigger", my function "sendEmail()" works only if I start it from script editor. I allowed sending emails on behalf of my at first time and then function works fine. But if I'm changing the value in the spreadsheet - function "onEdit(e)" processes new data but function "sendEmail()" does nothing.
I partly solved this problem by using project's triggers from "current project's triggers" menu. In that case, function "sendEmail()" works properly, but I have no access to the information about update.
For my purposes I could use just second way and find new values "manually" every time, but I wish to optimize this work.
So, my questions are:
Is the process I described above proper or I made a mistake
anywhere?
If process proper, is where a way to combine both cases?
Thanks!
You correctly understood that (as the docs say) simple triggers cannot send an email, because they run without authorization. An installable trigger, created via Resources menu, can: it has the same rights as the user who created the trigger. If it is set to fire on edit, it will get the same type of event object as a simple trigger does.
So, a minimal example would be like this, set to run "on edit":
function sendMail(e) {
MailApp.sendEmail('user#gmail.com', 'sheet edited', JSON.stringify(e));
}
It emails the whole event object in JSON format.
Aside: if your script only needs to send email but not read it, use MailApp instead of GmailApp to keep the scope of permissions more narrow.

Alfresco: How to see the data of a finished task in the next task?

I need pass data of a task1 (form of task1) to other task (form of task2), and see this data in the form of task2. I use one aspect for this and I have the next code (a part) for the taskListener (event: complete) in task1:
execution.setVariable('wf_data1', task.getVariable('wf_data1'));
In my task2, in the share-config-custom.xml, I have the wf_data1 in the form, but this shows empty.
Why happen this? How to see the wf_data1 in task2?
UPDATE:
The reason of why this not working is which in the file service-context.xml, the redeploy key is "false". I changed this to "true" and all is working.
Greetings,
Arak.
I'm not going to dive into your model and ways of showing it. Alfresco keeps track of the workflow history. I'm not sure till what detail(with/without aspects) is available, but it's quite easy to find out.
With this you can access workflow data in a next task. Just create a custom workflow form controller which retrieves data.

Refresh or Clear GUI (Apps Script Gadget Embedded in Google Site)

I have a small form that my colleagues and I often fill out that can be seen here, with source code (view-only) here. The spreadsheet that this form posts to can be seen (view-only) here.
Basically, the apps script is solely for preventing my coworkers from having to scroll through thousands of rows of a spreadsheet (this is also used for our film collection) to check in/out inventory. It will also, soon, post detailed history of the checkout in an audit spreadsheet.
I have attempted, with no success, to clear the values of the text fields after the data has been posted to the spreadsheet. What I essentially want to do is restart the GUI so that the fields are once again blank.
I have tried accessing the text fields by id but the return type is a Generic widget, which I of course can't do anything with. And since control is passed to the handler functions, the text fields can't be accessed, or at least I can't figure out how (and I looked through the documentation and online solutions for hours last night).
So the question: how can I erase/clear the values of the text fields in the GUI after values have been posted to the spreadsheet? (return from handler function to access text fields again, or restart the GUI?
I can accomplish restarting the script runs on a spreadsheet, but I have not been able to do this when it is embedded in a Google site.
The getElementById('xxxxx').setText('') approach was the right way to do it. but the way you tried to test it doesn't work... the new value would only be available in the next handler call.
/*
This function only has the desired effect if it is called within the handler
function (not within a nested function in the handler function).
*/
function restartGUI() {
var gui = UiApp.getActiveApplication();
gui.getElementById('equipmentIDField1').setText('');
gui.getElementById('equipmentIDField2').setText('');
gui.getElementById('equipmentIDField3').setText('');
gui.getElementById('studentLastNameField').setText('');
gui.getElementById('labasstLastNameField').setText('');
return gui;
}