NULL values in Crystal Reports - sql

I am trying to produce a Crystal Report showing MAIN and ALTERNATE contact details for our customers.
All works fine if the customer has both types of addresses (i.e. MAIN and ALTERNATE) but no report comes out at all for customers who only have a MAIN address. So, to summarise, all customers will have a MAIN address but only some will MAIN and ALTERNATE addresses.
I need to get the report to print sheets for all customers where or not the second address (in this case in our database as Addresses2.AddressType is ALTERNATE or NULL).
My selection formula is shown below:
{SubscriptionMembers.Current} and
{Categories.CategoryType} = "M" and
{SubscriptionMembers.MainSubscription} and
{Addresses.AddressType} in ["MAIN"] and
{Addresses2.AddressType} in ["ALTERNATE"] and
{Addresses.Country} = "United Kingdom" and
not {SubscriptionMembers.Lapsed} and
not {Contacts.Deleted}

I would recommend to use SQL Expression Field, containing something like (isnull({Addresses2.AddressType}, 'ALTERNATE')) and use this field in record selection formula - this way you do not depend on report options about handling NULL values etc.

Because only some have an 'Alternative address', the selection formula is only going to show customers with a 'main' AND 'alternative'.
I assume every customer has a main address
A way I would deal with this is take out {Addresses2.AddressType} in ["ALTERNATE"] and
and just drop the 'alternative' address details in the same section(group) as the main address.
As long as these are linked correctly it will display every customer from your other selection parameters, therefore will show 'main' and the customers who have an 'alternative' address.
How it should look:
Group - CustomerID
'MAIN' address details here 'ALTERNATE' address details here
Group - Details
'DATA' here

Since you need To get customer in either case then one way would be dont take address in record selection formula. Instead create a formula as to check null for address2
If isnull ({Addresses2.AddressType} in ["ALTERNATE"])
then your code
Else If (Addresses.AddressType} in ["MAIN"] or
{Addresses2.AddressType} in ["ALTERNATE"])
Then your calculation
This way you can handle easily

Related

How to use Prestashop Customer website field for cc email

Some customers require order emails to be sent for one more recipient (ie. accounting). So, as customer website field not used in shop, planned to use this. However, have trouble for getting data for classes/Mail.php
$website = Context::getContext()->customer->website;
does not get the data stored in customer website field. How to get this data from customer table website field correctly?
PS 1.7.8.7
All the rest seems doable, just set the value for cc field and it works.
So, found some solution. Not the nice one, as there will be extra query to DB, but it works.
$website = Db::getInstance()->getValue('SELECT `website` FROM `'._DB_PREFIX_.'customer` WHERE `email` = \''.($to).'\' ');

Filter parent data source with a field which is in another table in D365

Some times we need to filter a form grid based on the status of the transaction reference Id. Assume that we want to show purchase orders with confirm document state in arrival overview form. The document state field is located in the purch table. For this aim, I try to outer join WMSArrivalOverviewTmp to purch table and add Range. However the results is not as I expect.
This is the code I have tried in the initialized data source event:
[FormDataSourceEventHandler(formDataSourceStr(WMSArrivalOverview, WMSArrivalOverviewTmp), FormDataSourceEventType::Initialized)]
public static void WMSArrivalOverviewTmp_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
{
QueryBuildDataSource qbds = sender.queryBuildDataSource();
QueryBuildDataSource qbdsPO;
qbdsPO = qbds.addDataSource(tableNum(PurchTable));
qbdsPO.clearRange(fieldNum(PurchTable, DocumentState));
qbdsPO.joinMode(JoinMode::OuterJoin);
qbdsPO.fetchMode(QueryFetchMode::One2One);
qbdsPO.addLink(fieldNum(WMSArrivalOverviewTmp, InventTransRefId ),fieldNum(PurchTable, PurchId), qbds.name());
qbdsPO.relations(false);
qbdsPO.addRange(fieldNum(PurchTable, DocumentState)).value(SysQuery::value(VersioningDocumentState::Confirmed));
info(sender.query().toString());
}
This is the query which has been shown :
SELECT FIRSTFAST * FROM WMSArrivalOverviewTmp(WMSArrivalOverviewTmp)
OUTER JOIN FROM PurchTable(PurchTable_1) ON
WMSArrivalOverviewTmp.InventTransRefId = PurchTable.PurchId AND
((DocumentState = 40))
Also, I have changed the event type to query executing but I get errors:
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Error converting
data type nvarchar to bigint.
Cannot select a record in Purchase orders (PurchTable). The SQL
database has issued an error.
P.S. I have noticed that the error comes when I click on the update button after I fill one of the field in the filter section(arrival option). For example when I fill account number or warehouse. And also I have noticed that when I click on the update button while the fields are not filled in the filter section the join operation has not applied correctly, i.e., the purchase orders which have draft status are shown.
Your actual query looks correct to me. I would add that you may want to add the link between the WMSArrivalOverviewTmp.InventTransType == InventTransType::Purch (or set qbds.relations(true) so that you use the table's built in relation), but I doubt that is the root of your problem. Of course it wouldn't hurt to make sure your query works in the manner that you expect it to by converting the results of the info() call you have into SQL code and run it in SSMS to double check the result set.
Also, I'm curious why would you put the event on the datasource you are trying to manipulate? I would recommend investigating to see if it can occur on the OnModified event of the "status of the transaction reference Id". Although perhaps I am misunderstanding - if this situation is more of a "we need to happen all the time when the form loads" than a "some times we need" as you start your question off - the place to change the query is to modify it in a handler of the datasource's OnQueryExecuting event.
There are two ways of modifying the query on an event when an event occurs.
FormRun formRun = sender.formRun() as FormRun;
FormDataSource formDataSource = formRun.dataSource(formDataSourceStr(WMSArrivalOverview, WMSArrivalOverviewTmp));
//First way - get the base query and use executeQuery() to reload changes
Query query = formDataSource.query();
//modified query here.
formDataSource.executeQuery();
//Second way - get the current queryRun query and use research() to reload changes
Query query = formDataSource.queryRun.query();
//modified query here.
formDataSource.research();

WooCommerce: How to automatically select variation attribute dropdown field when there is only 1 option?

So I feel like this isn't too complicated of a request, but I simply can't figure it out. On my WooCommerce site, I have some variable products. There are 3 dropdown variation attributes in the following order (top to bottom): Color, Type, and Part Number. Each variation has a unique part number (only 1 part number per combination), so there is literally no need for the user to select the part number after they have chosen color & type. However, I need that part number to display for purposes of my product feed and so the customer can see the part number they have chosen by the previous 2 options.
My question is; since selecting a "Color" and "Type" narrows the final field ("Part number") down to only 1 option, how do I instruct WooCommerce to automatically select the single "part number" option that's available?
You can do this with JS:
jQuery('a.toggle_component').click(function(e){
if(!(jQuery(e.target).parents('.component').find('select.component_options_select > option[selected=selected]').val())) {
jQuery(e.target).parents('.component').find('select.component_options_select > option:nth-child(2)').attr('selected','selected');
jQuery(e.target).parents('.component').find('select.component_options_select').change();
}
});

MS Access 2010: Automatically Filters all the records depending on the user logged in

I am creating a database in Microsoft Access 2010 where when a user logged in the database, the user will only see records that is related to him or her. I've put a criteria in the record's query specifically in IssuingManager field which is [Forms]![frm_Home]![txtUser] but I always get enter parameter value when I run it. txtUser is an invisible text box in my main form so the records will have a reference on which records to filter. My main goal is to limit the user's data to their own records and hide or block them to others. I am new to access and still learning it. Any help or other ways I can filter the data or limit it to the records that is only related to the current user logged in is a big help.
This is my SQL code:
SELECT AdditionalFields.Status, tbl_NTE.CaseIDNo, tbl_NTE.EmployeeName,
tbl_PAH.DPosition, tbl_NTE.Function, tbl_NTE.IssuingManager,
tbl_NTE.ApprovingManager, tbl_NTE.ObjectOfViolation, tbl_NTE.Offense,
tbl_NTE.ClassPenalty, tbl_NTE.CorrectiveActionPenalty,
tbl_NTE.ObjectOfViolation2, tbl_NTE.Offense2, tbl_NTE.ClassPenalty2,
tbl_NTE.ObjectOfViolation3, tbl_NTE.CorrectiveActionPenalty2,
tbl_NTE.Offense3, tbl_NTE.ClassPenalty3, tbl_NTE.ObjectOfViolation4,
tbl_NTE.CorrectiveActionPenalty3, tbl_NTE.Offense4, tbl_NTE.ClassPenalty4,
tbl_NTE.CorrectiveActionPenalty4, tbl_NTE.DatesWhenActsWasWereCommited,
tbl_NTE.DatesWhenActsWasWereDiscovered, tbl_NTE.NTEDate,
tbl_NTE.NTELastDateModified, tbl_NTE.NTELastTimeModified,
tbl_NTE.NTELastUser, tbl_PAH.PAHDate, tbl_PAH.PAHLastDateModified,
tbl_PAH.PAHLastTimeModified, tbl_PAH.PAHLastUser, tbl_NCA.NCADate,
tbl_NCA.NCALastDateModified, tbl_NCA.NCALastTimeModified,
tbl_NCA.NCALastUser, tbl_NTE.EndorsedNTENoticeToHR,
tbl_NTE.EndorsementOfNTEToIS, tbl_NTE.DateReceivedNTEByTheEmployee,
tbl_NTE.SubmissionOfWEtoIS, tbl_NTE.SubmissionOfWEtoHRER,
tbl_NTE.InitialDecision, tbl_PAH.ScheduleForPAH, tbl_PAH.Recommendation,
tbl_PAH.EndorsementOfDecisionNoticeFromPAHCommitteeChairToHR,
tbl_PAH.EndorsementOfFinalizedPAHRecommendationToIS,
tbl_NCA.EndorsementOfDA2ToHRForReview, tbl_NCA.EndorsementOfReviewedDA2ToIS,
tbl_NCA.EmployeeAcceptanceOfDecision,
AdditionalFields.DescriptionOfPenaltyFinalDecision,
AdditionalFields.ApplicableDatesofEffectivity, AdditionalFields.Remarks,
AdditionalFields.RunningTAT, AdditionalFields.TAT, tbl_NTE.EHRID,
tbl_NTE.IssuingManagerEmailAddress, tbl_NTE.WrittenExplanationDueDate,
tbl_NTE.OffenseNo5, tbl_NTE.Offense5, tbl_NTE.ObjectOfViolation5,
tbl_NTE.ClassPenalty5, tbl_NTE.CorrectiveActionPenalty5, tbl_NTE.OffenseNo6,
tbl_NTE.Offense6, tbl_NTE.ObjectOfViolation6, tbl_NTE.ClassPenalty6,
tbl_NTE.CorrectiveActionPenalty6, tbl_NTE.OffenseNo7, tbl_NTE.Offense7,
tbl_NTE.ObjectOfViolation7, tbl_NTE.ClassPenalty7,
tbl_NTE.CorrectiveActionPenalty7
FROM (tbl_Worker INNER JOIN ((tbl_PAH INNER JOIN tbl_NCA ON tbl_PAH.
[CaseIDNo] = tbl_NCA.[CaseIDNo]) INNER JOIN AdditionalFields ON
tbl_NCA.CaseIDNo = AdditionalFields.CaseIDNo) ON tbl_Worker.WorkerID =
tbl_NCA.NameOfIssuingManager) INNER JOIN tbl_NTE ON (tbl_NTE.CaseIDNo =
tbl_PAH.CaseIDNo) AND (tbl_Worker.WorkerName = tbl_NTE.IssuingManager)
WHERE (((tbl_NTE.IssuingManager)=[Forms]![frm_Home]![txtUser]));
I would recommend to avoid using form's field references in queries at all. If form closed, the query will request parameter, like most likely in your case.
Replace the reference by global function created in standard module. This function can store the name, for instance, in static/global variable or retrieve it from table. Main or login form can set this variable/table record once, then the form can be closed without affecting queries functionality
Add another column and put the username. So when selecting the records, there's a condition where user='username'. They look all the data base on what the username has.
your method is fine & correct; you just have some sort of cockpit implementation error
the criteria in the query should be: Forms!frm_Home.txtUser
you could have a spelling error in your form name or text box name
make the textbox visible and enter a valid entry and run the query manually
what you are getting appears to be a parameter prompt that means it cannot find the object i.e. form named frm_Home

Multiple change of lotus type groups

maybe someone once wrote a script for mass change of lotus type groups? Mass but not all, only grups with first two characters begins on ('GD') i need change mostly type from mail only (3) to Multipurpose (0).
Just select the groups, create an agent with this code, that runs on selected documents:
FIELD GroupType := "0";
If you really want to do the selection in your agent, then let it run on "all documents in view" and add a selection before the action:
SELECT #Begins( ListName ; "GD" );
FIELD GroupType := "0";
As this will run a lot slower I would manually select the groups and use the first agent as selecting is as easy as setting the cursor to the first group with "GD", then scroll down to the last one and click it while holding the Shift- Key.