Can I change MaterialSwitch to true/false instead of on/off? - cosmicmind

Anyway I can change MaterialSwitch to return true/false instead of on/off?
print(switch.switchState) // prints true

you could just run print(not switch.switchState)

Hearing nothing else, I improvised and created a new bool variable. Then I just used if statements to set it correctly by accessing the hashValue.
if self.option1.switchState.hashValue == 1 {
option1Value = false
} else {
option1Value = true
}

Related

SuiteScript 2.0: Rescheduling a Scheduled Script With Checkbox Parameter

I have a scheduled script that does two things. I have checkbox parameters to determine if those things are require on this run of the script. The first time around both are defaulted to true.
function execute(scriptContext) {
var script = runtime.getCurrentScript();
doTask1 = script.getParameter({name: "custscript_tmh_do_task1"});
doTask2 = script.getParameter({name: "custscript_tmh_do_task2"});
if(doTask1){
//Do something
}
if(doTask2){
//Do something
}
//Determine if task1 or task2 needs to happen and set them to true or false.
//Reschedule script if required
if(doTask1 || doTask2){
var scheduledScriptTask = task.create({
taskType: task.TaskType.SCHEDULED_SCRIPT
});
scheduledScriptTask.scriptId = runtime.getCurrentScript().id;
scheduledScriptTask.deploymentId = runtime.getCurrentScript().deploymentId;
scheduledScriptTask.params = {'custscript_tmh_do_task1': doTask1 ,
'custscript_tmh_do_task2': doTask2 };
return scheduledScriptTask.submit();
}
}
The problem is the second time around, it is not doing the tasks when the booleans are set to true. It just skips over them. I have used the debugger to confirm at the point of rescheduling the script the booleans are true.
Question: How do I reschedule a scheduled script with setting a boolean value.
Side Question" I have the parameters created as a script parameter. Is it possible to do this without setting the script parameters in NetSuite?
that's not the correct constructor for generating the task. I always use:
var scheduledScriptTask = task.create({
taskType: task.TaskType.SCHEDULED_SCRIPT,
scriptId: runtime.getCurrentScript().id,
deploymentId: runtime.getCurrentScript().deploymentId,
params: {'custscript_tmh_do_task1': doTask1 ,
'custscript_tmh_do_task2': doTask2 }
});
Also script parameters are passed as strings so you need to convert.
either:
doTask1 = 'T' == script.getParameter({name: "custscript_tmh_do_task1"});
or
doTask1 = script.getParameter({name: "custscript_tmh_do_task1"});
...
if('T' == doTask1){ ...
Checking when you use them ('T' == doTask1) lets you just round trip the string values into your next iteration. If you use them as booleans so you can decide whether the next iteration needs to do both tasks then you'll need to turn them back to strings when you pass them to the next iteration: custscript_tmh_do_task1 : doTask1 ? 'T' : 'F'
You do not need to give the parameters default values in order to pass them on to the next iteration. And any values you give in the task.create method will override the configured values.

Writing if conditions in Excel

I am writing some if conditions in excel and i don`t succeed. I would glad if you can help me.
I want to write the following if condition(Pseudo code):
If(L28 appears between C44:C47)
{
Value = D31
}
else if( L28 ==C48)
{
Value = D32
}
If(L28 appears between C49:C53)
{
Value = D30
}
else If(L28 appears between C54:C57)
{
Value = D29
}
else
{
Value = L28
}
I have written the following part of code, but it is does not work.
"=IF(COUNTIF(C44:C47,L28),D31,if(L28=C48,D32,if(COUNTIF(C49:C53,L28),D30,if(COUNTIF(C54:C57,L28),D29))))"
Well, try this, but I have not tested it:
=if(iferror(match(L28,C44:C47,0),0)>0,D31,if(L28=C48,D32,if(iferror(match(L28,CC49:C53,0),0)>0,D30,if(iferror(match(L28,C54:C57,0),0)>0,D29,L28))))
Excel has a new ifs() function in one of the latest updates.
ifs(condition1, value1, condition2, value2,...) outputs the value for the first condition that is true.
that could simplify the formula a bit. No more need for nested if(). Below is Solar Mikes solution with ifs().
=ifs(iferror(match(L28,C44:C47,0),0)>0,D31,L28=C48,D32,iferror(match(L28,CC49:C53,0),0)>0,D30,iferror(match(L28,C54:C57,0),0>0,D29,L28)

Passing params to V93K test_suites.add method

This is in reference to this question. I checked our test interface and we are only passing the V93k primary params to the test_suites.add method.
V93K_PRIMARIES = [:lev_equ_set, :lev_spec_set, :timset, :tim_equ_set, :tim_spec_set, :seqlbl, :levset]
primary_tm_params = {}.tap do |primary_hash|
V93K_PRIMARIES.each do |param|
primary_hash[param] = tm_params.delete(param) unless tm_params[param].nil?
end
end
# Create the test suite
t = test_suites.add(test_name, primary_tm_params)
t.test_method = test_methods.amd93k.send(options[:tm].to_sym, tm_params)
V93K_PRIMARIES.each do |primary|
t.send("#{primary}=", primary_tm_params[primary]) unless primary_tm_params[primary].nil?
end
# Insert the test into the flow
test(t, tm_params)
When I set a breakpoint, I do see they were missing. Here they are after updating the code:
:ip=>:L2,
:testmode=>:speed,
:cond=>:pmax,
:if_failed=>:cpu_pmin,
:testtype=>:cpu,
:test_ip=>:bist,
:tm=>"Bist"}
And here is the .tf file generated from the original two tests in the original question:
run_and_branch(cpu_L2_speed_pmin_965EA18)
then
{
}
else
{
#CPU_PMIN_965EA18_FAILED = 1;
}
if #CPU_PMIN_965EA18_FAILED == 1 then
{
run(cpu_L2_speed_pmax_965EA18);
}
else
{
}
I think we have it figured out, thx very much!
The normal approach to this is just to pass everything to flow.test, rather than a subset of the options passed from the flow.
It will only act on the options it recognizes, which are basically the flow control parameters (:id, :if_failed, :unless_enabled, etc) and the test and bin number parameters, and it will just ignore the rest.

text field attributes/methods dynamics crm 2011

I'm looking a method or way how to check that the text field in crm form is "null"
I've got a tab, there are section and text field inside of it;
furthermore, I'm using that function in order to hide/show tab.
function setVisibleTabSection(tabname, TextFieldName, show) {
var tab = Xrm.Page.ui.tabs.get(tabname);
if (tab != null) {
if (TextFieldName == null)
tab.setVisible(show);
else {
var section = Xrm.Page.data.entity.attributes.get(TextFieldName).getValue();
if (section != null) {
show == true;
tab.setVisible(show);
}
}
}
}
however, It doesn't work. There is nothing inside of the text box, and the tab expanded anyway.
by the way, parameters, which I give the function: "tab_8", "new_conf_report", false
where the secon one the name of the text field
Try
if (section != null && section !="")...
You may find that a field which is initially blank is null, whereas one from which you have deleted content but not yet saved the form is simply an empty string.
Certainly worth a shot.
show==true
is incorrect as others have pointed out (needs to be show=true) but is simply redundant as written inside the same IF statement, just replace next line as:
tab.setVisible(true);
It is possible you intended "show" to be the default tab state to use if text field is not empty, in which case just move this line outside the IF instead of changing it (as shown below)
It looks like the construction using the third "show" parameter is to allow you to use the function to set the tab state to a specific state of shown or not without looking for a text field value at all. You would need to pass parameters as eg tabname,,true - you might consider swapping the TextFieldName and Show parameters so it is easier to just drop the third rather than remember to double-comma.
While we're fixing stuff, lets replace that variable "section" with something with a more meaningful name:
function setVisibleTabSection(tabname, show, TextFieldName) //usage: show is state Tab will have if no TextFieldName is specified, or if text field is empty
{
var tab = Xrm.Page.ui.tabs.get(tabname);
if (tab != null)
{
if (show==null){show=true;}
if (TextFieldName == null)
{
tab.setVisible(show);
}
else
{
var strFieldValue = Xrm.Page.data.entity.attributes.get(TextFieldName).getValue();
if (strFieldValue != null && strFieldValue !="")
{show=true;}
tab.setVisible(show);
}
}
}
I don't see anything wrong with your Javascript (besides what Guido points out, which basically will only set the tab to visible if you pass in true for show). Use the debugging tool within IE by pushing F12, and set a break point at the top of your function to see where your logic is failing.
If you've never debugged javascript before, see http://social.technet.microsoft.com/wiki/contents/articles/3256.how-to-debug-jscript-in-microsoft-dynamics-crm-2011.aspx
or
How to debug jScript for Dynamics CRM?
I think there is a typo in the code:
show == true;
actually the code (assuming "=" instead of "==") will show always the tab if TextFieldName isn't empty, removing that line will show/hide the tab according to show parameter value
It seems to work when I run it but I'm not sure what you'd expect it to do so it might not be working the way you'd like it to. :)
function setVisibleTabSection(tabName, textFieldName, show) {
var tab = Xrm.Page.ui.tabs.get(tabName);
if(!tab) return;
if (!TextFieldName)
tab.setVisible(show);
else {
var section = Xrm.Page.data.entity.attributes.get(textFieldName).getValue();
if (section)
tab.setVisible(true);
}
}

Kohana 3.0 - Validate: Error if one of fields aren't empty

I have four fields. Lets call them a, b, c and d. I need to validate them.
Error is when:
One til three fields are not empty;
Error is not when:
All fields are not empty,
All fields are empty;
Any neat solution here? Thanks in advice.
Edit:
Only relationships are that all four variables are prefixed with event_. It gives me event_name, event_description etc..
Edit #2:
At the moment I have something like...
if (
!empty($values['event_date'])
&& !empty($values['event_time'])
&& !empty($values['event_name'])
&& !empty($values['event_description'])
) {
It checks that all fields are filled up and then, if that's true, adds event.
As I said before, I need to display user-friendly error when some field isn't filled up (for example, user had forgot to enter description). Anyway, when all fields are filled up (it means - all okay) or when no fields are filled up (it means - user ignores event adding and don't want to add one) - no error should be displayed.
I could write code with 16 'if' statements, but isn't there any better way? :)
This isn't beautiful, but as long as you have something unique about the fields you want to check (such as "event_..."), you could loop through the variable array ($values, $_POST, etc) and check only the fields that matter. Then, you can easily check for an all or none situation.
Here is a quick example:
$total = 0;
$filled = 0;
foreach($values as $field => $val) {
if(strpos($field,'event_') === 0) {
$total++;
if( ! empty($val)) {
$filled++;
}
}
}
if($filled == 0 OR $total == $filled) {
//PASS VALIDATION
} else {
//FAIL VALIDATION
}
Is there a relationship between one of the entered values and the none entered values??
could you just parse it as an empty value?
if ( ! isset($post->a) ) $post->a = '';

Resources