Validate Stored Procedure Success in Powerapps - sql-server

I am fairly new to powerapps, but it sounds like there is a major limitation on being able to return values for a SQL Server stored procedure.
I have an app that when you push a button pulls data from various controls on screen and submits it to a stored procedure. This is done by invoking a flow. The code is basically :
EditPuddles.Run(ActionDrop.Selected.Value, PuddlesText.Text,
ClassicDrop.Selected.Value, ServiceRates.Text, User().FullName)
The code works and does what it is supposed to. However, what I need now more than anything is it to tell me when it fails or succeeds.
Ideally I would have it return a values that I could use to determine if I should display a success or failure message. I get that I cannot return a data set, but it must at least be able to tell if there is an error.

I'm also new to PowerApps and Power Automate but I figured out a way to show results on success and an error message on failure, after a flow is executed.
PowerApps
For your example the code for the property "OnSelect" of the button should be:
UpdateContext({ PuddlesResult: EditPuddles.Run("a", "b", "c") });
If(
Not IsBlank(PuddlesResult.errormessage),
// on failure:
Notify(PuddlesResult.errormessage, NotificationType.Error, 5000),
// on success: (use PuddlesResult.ResultSets.Table1)
Notify("All good", NotificationType.Information, 5000)
)
Power Automate
Your flow in Power Automate should look like this:
Capture the error message
On error the action "Execute stored procedure (V2)" returns output:
To return the message in the output update the action "Respond to a PowerApp or flow":
Text: ErrorMessage
Expression: outputs('Execute_stored_procedure_(V2)')?['body']?['message']
Return the error message only on failure/timeouts
Select "Configure run after" on the action "Respond to PowerApp or flow":
And set it to only run this action on failure and time outs:
For returning normal results you can use action "Response" and set the "Configure run after" settings to "Is successful".
I hope this helps you and others as it took me a long time too to figure this out. But it will allow you to handle succes and failure appropriately in your PowerApp.

Related

How to apply condition IF...ELSE in MAF CUCUMBER

Currently, I have 2 cases in the following detail
I run an API with a file upload, after API is run successfully. There are 2 statuses it can be displayed
status = waiting
status = ready_to_process (this is the correct status if the system not have a problem)
NOTE: The status change like that is cause be system sometime can't change at the time file is uploaded, but it can be recorded to DB and run successfully
And then in the Database, data change is also different
Changed to the role: unknow
Changed to the role: pass
How can I write steps if..else in Cucumber use MAF framework like:
If API run then it returns status 1 => verify the result 1 in DB
Else
verify result 2 in DB
You can't write conditional code in Cucumber features. What you should be doing is writing a scenario for each condition. So you should write something like
Scenario: Run ends with waiting status
...
Scenario: Run ends with ready to process status
...

How to transalte messages that comes from server in react native app

I'm building a react-native app with spanish as default language, the problem is that I'm using a open source backend service to serve data and this data comes is in english by default. What I want is to transalate this data/messages that comes from server in my react-native app to show to the user the messages in spanish not in english.
This is the first time I am doing this process and it is not clear to me what are the steps or the flow that is generally followed for this kind of proces(translate messages that comes from server in my app).
You have many approaches to such a thing one comes to mind is
Catch the error/api response message which mostly server error messages comes in codes and messages.
set a condition statement if code equal 2 that means the server is down for example
Example:
You made a request to the server and there was an error with the server let say wrong username and password, now the server returns a message and a error code you have to get the code or the message and show your own message
.....made the request the server returned
{ code: 192, message: Wrong username/Password }
now in your code you will do the following
if(code == 192){
...do your message
}
P.S this is just on top my head since you didn't share any codes or responses from your server.
UPDATE :
If you want to translate all your strings/messages that comes from the server you would need to do another approche something like this
Create a file contain all the strings/codes from the server
compare messages/code comes from the server and the file will return the text you want
{ "102": "Hola", "103": "Bien", "104": "Nada", "105": "Si", }
now this file contain the error/message code all you have to do is when you receive the code grab the message from this file
let translation = {
"101": "Hola",
"102":"Si"
};
translation["102"]; // Result will be Si
Now this is the most accurate approach but you have to know all the messages/codes comes from the server, now if you want something to translate on the fly you might wanna use translation library and may not be accurate translation

How can I prevent accidentally overwriting an already existing database?

I'm adding BaseX to an existing web application and currently writing code to import data into it. The documentation is crystal-clear that
An existing database will be overwritten.
Finding this behavior mindboggingly dangerous, I tried it with the hope that the documentation was wrong but unfortunately my test confirmed it. For instance, using basexclient I can do this:
> create db test
Database 'test' created in 12.03 ms.
> create db test
Database 'test' created in 32.43 ms.
>
I can also replicate this behavior with the Python client, which is I what I'm actually using for my application. Reducing my code to the essentials:
session = BaseXClient.Session("127.0.0.1", 1984, "admin", "admin")
session.create("test", "")
It does not matter whether test exists or not, the whole thing is overwritten if it exists.
How can I work around this dangerous default behavior? I'd would like to prevent the possibility of missteps in production.
You can issue a list command before you create your database. For instance with the command line client if the database does not exist:
> list foo
Database 'foo' was not found.
Whereas if the database exists:
> list test
Input Path Type Content-Type Size
------------------------------------
This is a database that is empty so it does not show any contents but at least you do not get the error message. When you use a client you have to check whether it errors out or not. With the Python client you could do:
def exists(session, db):
try:
session.execute("list " + db)
except IOError as ex:
if ex.message == "Database '{0}' was not found.".format(db):
return False
raise
return True
The client raises IOError if the server raises an error, which is a very generic way to report a problem. So you have to test the error message to figure out what is going on. We reraise if it happens that the error message is not the one which pertains to our test. This way we don't swallow exceptions caused by unrelated issues.
With that function you could do:
session = BaseXClient.Session("127.0.0.1", 1984, "admin", "admin")
if exists(session, "test"):
raise SomeRelevantException("Oi! You are about to overwrite your database!")
session.create("test", "")

Salesforce Tooling API - Deactivate Trigger

I am attempting to deactivate triggers using the tooling API. I have successfully in a developer ORG. But was unable to do this in a real developer org. Is this a Salesforce tooling api bug?
Here is the basis of the algorithm,
Create a MetadataContainer with a unique Name
save MetadataContainer
Create an ApexTriggerMember setting the Body, MetadataContainerId, ContentEntityId, and Metadata[apiVersion=33.0 packageVersions=[] status="Inactive" urls=nil>]
Modify Metadata["status"]="Inactive"
save ApexTriggerMember
Create/Save ContainerAsyncRequest
monitor container until completed.
display errors if appropriate
In the sandbox, I have confirmed after requerying the Apex enter code hereTriggerMember that the read-only field "Content" looks appropriate. I also confirmed that the MetadataContainerId now points to a ContainerAsyncRequest that has a State of "Completed"
Here are my results, it appears to be a success, but the ApexTrigger is never deactivated
ContentEntityId = 01q.............[The ApexTrigger I want deactivated]
Content="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<ApexTrigger xmlns=\"urn:metadata.tooling.soap.sforce.com\">
<apiVersion>33.0</apiVersion>
<status>Inactive</status>
</ApexTrigger>"
Metadata={apiVersion=33.0 packageVersions=nil status="Inactive" urls=nil> attributes= {type="ApexTriggerMember"
url="/services/data/v33.0/tooling/sobjects/ ApexTriggerMember/401L0000000DCI8IAO"
}
}
I think you need to deploy the inactive Trigger from Sandbox to Production. You can't simply deactivate the Trigger in Production. This is true even in the UI.
There are other options, such as using a Custom Setting or Metadata Type to store a Run/Don't Run value. You would query that value in the Trigger to decide whether or not to run it.
https://developer.salesforce.com/forums/?id=906F0000000MJM9IAO

I'm unable to see system.debug statements on a trigger

I created a trigger that looks like this:
trigger DG_CM_Trigger on CampaignMember (before insert) {
System.debug('DG_CM_Trigger - START');
if (Trigger.isBefore && Trigger.isInsert){
DG_CampaignMember_Class.populateCustomAttributes(trigger.New);
}
System.debug('DG_CM_Trigger - END');
}
As you can see, I have system debug statements at the beginning and end of the trigger. When I look at the debug logs, I can see that the trigger is called...
09:42:46.524 (524616000)|CODE_UNIT_STARTED|[EXTERNAL]|01qc00000004eIV|DG_CM_Trigger on CampaignMember trigger event BeforeInsert for [new]
09:42:46.540 (540035000)|METHOD_ENTRY| [1]|01pc00000006aDT|DG_CampaignMember_Class.DG_CampaignMember_Class()
09:42:46.540 (540101000)|METHOD_EXIT|[1]|DG_CampaignMember_Class
09:42:46.540 (540725000)|METHOD_ENTRY|[4]|01pc00000006aDT|DG_CampaignMember_Class.populateCustomAttributes(LIST<CampaignMember>)
09:42:46.543 (543070000)|CONSTRUCTOR_ENTRY|[114]|01pc00000006aDT|<init>()
09:42:46.543 (543199000)|CONSTRUCTOR_EXIT|[114]|01pc00000006aDT|<init>()
09:42:46.543 (543273000)|METHOD_ENTRY|[114]|01pc00000006aDT|DG_CampaignMember_Class.LeadFieldMapping()
09:42:46.548 (548241000)|METHOD_ENTRY|[41]|01pc00000006aDT|DG_CampaignMember_Class.getCMFieldMapping()
09:42:46.693 (693286000)|METHOD_EXIT|[41]|01pc00000006aDT|DG_CampaignMember_Class.getCMFieldMapping()
09:42:46.703 (703469000)|METHOD_EXIT|[114]|01pc00000006aDT|DG_CampaignMember_Class.LeadFieldMapping()
09:42:46.781 (781457000)|METHOD_EXIT|[4]|01pc00000006aDT|DG_CampaignMember_Class.populateCustomAttributes(LIST<CampaignMember>)
09:42:46.781 (781790000)|CODE_UNIT_FINISHED|DG_CM_Trigger on CampaignMember trigger event BeforeInsert for [new]
However, I do not see my System.debug statement. I had debug statements in the class as well, but does do not show either. I have set the debug log filters to apex code: debug and system: debug (the rest are info). I even tried setting the 'override log filters' on the CampaignMember_Class and also set the levels to apex code: debug and system:debug. I can't seem to figure out why the debug statements are not showing up on the log which is making debugging extremely difficult. Peharps there is some kind of user setting I'm not aware of? User permissions? (although I'm in the admin profile, but I perhaps something in the profile settings that is not set?) Any help would be appreciated.
Try specifying the LoggingLevel as the first parameter to the System.debug calls. E.g.
System.debug(LoggingLevel.Error, 'hello');
Also, if this is a deployed managed package Salesforce will hide all logging.

Resources