I'm pretty new to powerapps but learning as I go. Is there a way to write the following if statements as one statement? (that way it will only create one item on my sharepoint list, instead of seperate items for each if statement). I am struggling to do so as each If statement has a different default result.
If(
IsEmpty(MondayCombo.SelectedItems),
Patch(
ChangeOfService,
Defaults(ChangeOfService),
{Monday: DataCardValue82.Text}
),
Patch(
ChangeOfService,
Defaults(ChangeOfService),
{
Monday: Concat(
MondayCombo.SelectedItems,
Value,
", "
)
}
)
);
If(
IsEmpty(TuesdayCombo.SelectedItems),
Patch(
ChangeOfService,
Defaults(ChangeOfService),
{Tuesday: DataCardValue83.Text}
),
Patch(
ChangeOfService,
Defaults(ChangeOfService),
{
Tuesday: Concat(
TuesdayCombo.SelectedItems,
Value,
", "
)
}
)
);
If(
IsEmpty(WednesdayCombo.SelectedItems),
Patch(
ChangeOfService,
Defaults(ChangeOfService),
{Wednesday: DataCardValue84.Text}
),
Patch(
ChangeOfService,
Defaults(ChangeOfService),
{
Wednesday: Concat(
WednesdayCombo.SelectedItems,
Value,
", "
)
}
)
);
If(
IsEmpty(ThursdayCombo.SelectedItems),
Patch(
ChangeOfService,
Defaults(ChangeOfService),
{Thursday: DataCardValue85.Text}
),
Patch(
ChangeOfService,
Defaults(ChangeOfService),
{
Thursday: Concat(
ThursdayCombo.SelectedItems,
Value,
", "
)
}
)
);
Unfortunately PowerApps don't have the return or exit command yet to break the code execution.
You have to come up with a workaround to verify the code execution & bypass all the other unwanted code execution. For example, we can have a bool variable to set & validate in next loop.
UpdateContext({RecordCreated:false});
If(
IsEmpty(MondayCombo.SelectedItems),
UpdateContext({RecordCreated:true});
Patch(
ChangeOfService,
Defaults(ChangeOfService),
{Monday: DataCardValue82.Text}
),
UpdateContext({RecordCreated:true});
Patch(
ChangeOfService,
Defaults(ChangeOfService),
{
Monday: Concat(
MondayCombo.SelectedItems,
Value,
", "
)
}
)
);
If(RecordCreated = false,
If(
IsEmpty(TuesdayCombo.SelectedItems),
Patch(
ChangeOfService,
Defaults(ChangeOfService),
{Tuesday: DataCardValue83.Text}
),
Patch(
ChangeOfService,
Defaults(ChangeOfService),
{
Tuesday: Concat(
TuesdayCombo.SelectedItems,
Value,
", "
)
}
)
);)
Please up-vote this idea
Related
i have two future methods
Future<List> getTrns(String token,int page,) async {
final response = await
http.get(Uri.parse("api1/?params" ),
headers:{
....
});
final String t = response.body;
List list =jsonDecode(t)['data'];
return list;
}
Future<String> getstate(String code,String token,DateTime now) async {
DateTime start_date = new DateTime(now.year, now.month, now.day);
String stat='';
final response = await
http.get(Uri.parse("api2/?params" ),
headers:{
...
});
final String t = response.body;
List l = jsonDecode(t)['data'];
if(l.length == 0){
stat = "absent";
}else {
stat = "present";
}
return stat;
}
this first methode will get the list of employee while the second one will use each employee code to find their state from another api.. the two functions are working fine but displaying them in an Datatable gave me an error of
Instance of future<string>
Only in the stat cell while other cells are working fine
here's how i built the table
body: Column( children: <Widget>[
FutureBuilder<List>(
future: getTrns(widget.token,widget.page),
builder: (ctx,ss){
if(ss.hasError){
print("error");
}
if(ss.hasData){
datalist=ss.data!;
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: _createDataTable(),
)
);
}else {
return Center(child: CircularProgressIndicator());
}
}
),
MaterialButton(onPressed: () {
widget.page = widget.page+1;
print(widget.page);
},
child: Text("Next"),
color: Colors.blue,)
]
)
)
);
}
DataTable _createDataTable() {
return DataTable(columns: _createColumns(), rows: _createRows());
}
List<DataColumn> _createColumns() {
return [
DataColumn(label: Text('ID')),
DataColumn(label: Text('Full Name')),
DataColumn(label: Text('State'))
];
}
List<DataRow> _createRows() {
return datalist
.map((list) => DataRow(cells: [
DataCell(
Text(list['emp_code'].toString()),
onTap: (){
Navigator.of(context).push(
MaterialPageRoute(builder: (BuildContext context)=>Details(token: w idget.token, emp:list['emp_code'].toString())
));
}
),
DataCell(
Text(list['first_name'].toString()+" "+list['last_name'].toString()),
onTap: (){
Navigator.of(context).push(
MaterialPageRoute(builder: (BuildContext context)=>Details(token: widget.token, emp:list['emp_code'].toString())
));
}
),
DataCell(Text( getstate(list['emp_code'], widget.token, widget.now).toString() ),
onTap: (){
Navigator.of(context).push(
MaterialPageRoute(builder: (BuildContext context)=>Details(token: widget.token, emp:list['emp_code'].toString())
));
}
)
]))
.toList();
}
}
this is the result
table screenshot
Edit1: new cell code cell code
the error is random, sometimes in first celland sometimes in a different one
first result
another result
You will need another FutureBuilder around getstate just as you did with getTrns.
Your code already demonstrates that you know how to use one, so I will not bore you with it.
If you need a refresher: What is a Future and how do I use it?
You may want to put your Future, into a variable instead of directly refering to them in your FutureBuilders though, because you want to keep the same Future (or rather it's probably already existing result) when the user trigger a rebuild that has nothing to do with your data, for example by tilting the screen of their device or changing the size of their browser or desktop window.
Try this
final Map<String, dynamic> t = response.body;
list =jsonDecode(t)['data'] as Map<String, dynamic>;
return list;
i tried the below code.
{
"Topic": "If statement",
"C": "if ( condition )\r\n { code ;}\r\nelse if( condition )\r\n { code; }\r\nelse \r\n { code; }",
"C++": "if ( condition )\r\n { code ;}\r\nelse if( condition )\r\n { code; }\r\nelse \r\n { code; }",
"JAVA": "if ( condition )\r\n { code ;}\r\nelse if( condition )\r\n { code; }\r\nelse \r\n { code; }",
"PHP": "if ( condition )\r\n { code ;}\r\nelse if( condition )\r\n { code; }\r\nelse \r\n { code; }",
"JS": "if ( condition )\r\n { code ;}\r\nelse if( condition )\r\n { code; }\r\nelse \r\n { code; }",
"PL/SQL": "if (conditio) then \r\n {code;}\r\nelsif (conditon) then \r\n {code;}\r\nelse \r\n {code;}",
"VBNET": "If condition Then\r\n code\r\nElse If condition Then\r\n code\r\nElse\r\n code\r\nEnd If",
"PYTHON": "if ( condition ):\r\n code\r\nelif ( condition ):\r\n code\r\nelse: \r\n code"
},
But new line is not showing.1
From here:
The textarea formater shows text with carriage returns intact (great for multiline text), this formatter will also adjust the height of rows to fit the cells contents when columns are resized.
{title:"Example", field:"example", formatter:"textarea"}
In Java I want to add a column to a dataframe with the value looked up in a map using the value from a column, like this
.withColumn( "lookup" , lit( sizes.value( ).floorEntry( col( "integer" ) ).getValue( ) ) )
but this results in an exception
Caused by: java.lang.ClassCastException: org.apache.spark.sql.Column cannot be cast to java.lang.Comparable
at java.util.TreeMap.compare(TreeMap.java:1290)
If I use a fixed value for the key the lookup works
.withColumn( "lookup" , lit( sizes.value( ).floorEntry( 28 ).getValue( ) ) )
Is what I am attempting possible?
Note that the map is a 'NavigableMap' to get closest matches, and it has been broadcast.
The code with the problem line commented out
final Broadcast< NavigableMap > sizes = spark.sparkContext( )
.broadcast(
new NavigableMapBuilder<Integer, Integer>()
.put( 13, 8000 )
.put( 16, 6905 )
.put( 27, 1894 )
.put( 29, 2107 )
.get() ,
classTag( NavigableMap.class )
);
final Dataset< Row > extract = spark.createDataFrame(
asList(
create( "C000001573", new Date( 119, 8 ,13 ) , 13 ),
create( "C000001573", new Date( 119, 8 ,14 ) , 16 ),
create( "C000001573", new Date( 119, 8 ,15 ) , 27 ),
create( "C000001573", new Date( 119, 8 ,16 ) , 29 )
) ,
DataTypes.createStructType(
new StructField[] {
DataTypes.createStructField( "key", DataTypes.StringType, false),
DataTypes.createStructField( "date", DataTypes.DateType, false),
DataTypes.createStructField( "integer", DataTypes.IntegerType, false)
}
)
);
extract
.withColumn( "multiply" , col( "integer" ).multiply( 10 ) )
// .withColumn( "lookup" , lit( sizes.value( ).floorEntry( col( "integer" ) ).getValue( ) ) )
.withColumn( "lookup" , lit( sizes.value( ).floorEntry( 28 ).getValue( ) ) )
.withColumn( "copy" , col( "date" ) )
.show();
and
public class NavigableMapBuilder<K, V> {
private final NavigableMap<K, V> map = new TreeMap<>();
public NavigableMapBuilder<K,V> put( K key, V value) {
this.map.put(key, value);
return this;
}
public NavigableMap<K, V> get() {
return this.map;
}
}
which generates this output
+----------+----------+-------+--------+------+----------+
| key| date|integer|multiply|lookup| extra|
+----------+----------+-------+--------+------+----------+
|C000001573|2019-09-13| 13| 130| 1894|2019-09-13|
|C000001573|2019-09-14| 16| 160| 1894|2019-09-14|
|C000001573|2019-09-15| 27| 270| 1894|2019-09-15|
|C000001573|2019-09-16| 29| 290| 1894|2019-09-16|
+----------+----------+-------+--------+------+----------+
One way is to use a user defined function: I referenced Apache Spark in Action version 2 MEAP for this.
The function
import org.apache.spark.broadcast.Broadcast;
import org.apache.spark.sql.api.java.UDF1;
import java.util.NavigableMap;
public class SizeLookup implements UDF1<Integer,Integer> {
private final Broadcast< NavigableMap > sizes;
public SizeLookup(Broadcast< NavigableMap > sizes ){
this.sizes = sizes;
}
#Override
public Integer call( Integer key ) {
return (Integer)sizes.value( ).floorEntry( key ).getValue( );
}
}
The code example updated to use it
final Broadcast< NavigableMap > sizes = spark.sparkContext( )
.broadcast(
new NavigableMapBuilder<Integer, Integer>()
.put( 13, 8000 )
.put( 16, 6905 )
.put( 27, 1894 )
.put( 29, 2107 )
.get() ,
classTag( NavigableMap.class )
);
spark.udf().register( "lookupSize", new SizeLookup( sizes ) , DataTypes.IntegerType );
final Dataset< Row > extract = spark.createDataFrame(
asList(
create( "C000001573", new Date( 119, 8 ,13 ) , 13 ),
create( "C000001573", new Date( 119, 8 ,14 ) , 14 ),
create( "C000001573", new Date( 119, 8 ,15 ) , 27 ),
create( "C000001573", new Date( 119, 8 ,16 ) , 29 )
) ,
DataTypes.createStructType(
new StructField[] {
DataTypes.createStructField( "key", DataTypes.StringType, false),
DataTypes.createStructField( "date", DataTypes.DateType, false),
DataTypes.createStructField( "integer", DataTypes.IntegerType, false)
}
)
);
extract
.withColumn( "multiply" , col( "integer" ).multiply( 10 ) )
.withColumn( "lookup" , callUDF( "lookupSize", col( "integer" ) ) )
.withColumn( "copy" , col( "date" ) )
.show();
This was easy to implement. Apparently it can be used in spark sql as well but I haven't tried.
I am working on a function to find a field from any form based on the label text. I'd like to return different attributes of the field so that I can use them later.
Originally, I just needed the value of the field, so I used the work here to return the value of a field based on the label:
function itsg_get_value_by_label( $form, $entry, $label ) {
foreach ( $form['fields'] as $field ) {
$lead_key = $field->label;
if ( strToLower( $lead_key ) == strToLower( $label ) ) {
return $entry[ $field->id ];
}
}
return false;
}
I get my value by setting a variable and passing in the field label that I'm looking for:
$mobile_phone = itsg_get_value_by_label( $form, $entry, "Mobile Phone" );
Later on, as I continued to work on my solution, I found that I also needed to find those fields and return the ID. Initially, I wrote the same function and just returned the ID, but I'd like to make the solution more efficient by rewriting the function to return multiple field attributes in an array, as such:
function get_field_atts_by_label( $form, $entry, $label ) {
foreach ( $form['fields'] as $field ) {
$lead_key = $field->label;
if ( strToLower( $lead_key ) == strToLower( $label ) ) {
$field_atts = array(
'value' => $entry[ $field->id ],
'id' => $field->id,
);
return $field_atts;
}
}
return false;
}
My problem now is that I am not quite sure how to retrieve the specific attributes from my function and set them to a variable.
Well, I'll go ahead and answer my own question. Such a simple solution to this one. Had a momentary brain fart.
$mobile_phone = get_field_atts_by_label( $form, $entry, "Mobile Phone" );
$mobile_phone_id = $mobile_phone['id'];
$mobile_phone_value = $mobile_phone['value'];
I have installed a plugin from this question -->
Show most recent search terms in wordpress. I have the plugin working on my site, but i would like to ask that, how to clear the recent searched keywords that displaying on my website. I am running out of idea how to make it happen.
As you can see the result from my site: www.ncc.my. There are now 10 keywords on top of search box. I want to clear all the keyword. I have searched over the google but yet to get the answer. Here is the php code of the widget. See if you can get the solution to clear the keywords. Thanks!
<?php
/*
Plugin Name: Recent Searches Widget
Plugin URI: http://www.poradnik-webmastera.com/projekty/recent_searches_widget/
Description: Shows recent searches in a sidebar widget.
Author: Daniel Frużyński
Version: 1.2
Author URI: http://www.poradnik-webmastera.com/
Text Domain: recent-searches-widget
*/
/* Copyright 2009-2010 Daniel Frużyński (email : daniel [A-T] poradnik-webmastera.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
if ( !class_exists( 'RecentSearchesWidget' ) ) {
class RecentSearchesWidget {
// Constructor
function RecentSearchesWidget() {
// Initialize plugin
add_action( 'init', array( &$this, 'init' ) );
// Page load
add_action( 'template_redirect', array( &$this, 'template_redirect' ) );
// Widgets initialization
add_action( 'widgets_init', array( &$this, 'widgets_init' ) );
}
// Plugin initialization
function init() {
load_plugin_textdomain( 'recent-searches-widget', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
}
// Page load
function template_redirect() {
if ( is_search() ) {
// Store search term
$query = $this->strtolower( trim( get_search_query() ) );
$options = get_option( 'recent_searches_widget' );
if ( !is_array( $options ) ) {
$options = $this->get_default_options();
}
$max = $options['max'];
$data = get_option( 'recent_searches_widget_data', array() );
if ( !is_array( $data ) ) {
if ( isset( $options['data'] ) ) {
$data = $options['data'];
unset( $options['data'] );
update_option( 'recent_searches_widget', $options );
}
if ( !is_array( $data ) ) {
$data = array();
}
}
$pos = array_search( $query, $data );
if ( $pos !== false ) {
if ( $pos != 0 ) {
$data = array_merge( array_slice( $data, 0, $pos ),
array( $query ), array_slice( $data, $pos + 1 ) );
}
} else {
array_unshift( $data, $query );
if ( count( $data ) > $max ) {
array_pop( $data );
}
}
update_option( 'recent_searches_widget_data', $data );
}
}
// Widgets initialization
function widgets_init() {
$widget_ops = array(
'classname' => 'widget_rsw',
'description' => __('Shows recent searches', 'recent-searches-widget'),
);
wp_register_sidebar_widget( 'recentsearcheswidget', __('Recent Searches', 'recent-searches-widget'),
array( &$this, 'widget_rsw' ), $widget_ops );
wp_register_widget_control( 'recentsearcheswidget', __('Recent Searches', 'recent-searches-widget'),
array( &$this, 'widget_rsw_control' ) );
}
function widget_rsw( $args ) {
extract( $args );
$title = isset( $options['title'] ) ? $options['title'] : '';
$title = apply_filters( 'widget_title', $title );
if ( empty($title) )
$title = ' ';
echo $before_widget . $before_title . $title . $after_title, "\n";
$this->show_recent_searches( "<ul>\n<li>", "</li>\n</ul>", "</li>\n<li>" );
echo $after_widget;
}
function show_recent_searches( $before_list, $after_list, $between_items ) {
$options = get_option( 'recent_searches_widget' );
if ( !is_array( $options ) ) {
$options = $this->get_default_options();
}
$data = get_option( 'recent_searches_widget_data' );
if ( !is_array( $data ) ) {
if ( isset( $options['data'] ) ) {
$data = $options['data'];
}
if ( !is_array( $data ) ) {
$data = array();
}
}
if ( count( $data ) > 0 ) {
echo $before_list;
$first = true;
foreach ( $data as $search ) {
if ( $first ) {
$first = false;
} else {
echo $between_items;
}
echo '<a href="', get_search_link( $search ), '"';
if ( $options['nofollow'] ) {
echo ' rel="nofollow"';
}
echo '>', wp_specialchars( $search ), '</a>';
}
echo $after_list, "\n";
} else {
_e('No searches yet', 'recent-searches-widget');
}
}
function widget_rsw_control() {
$options = $newoptions = get_option('recent_searches_widget', array() );
if ( count( $options ) == 0 ) {
$options = $this->get_default_options();
update_option( 'recent_searches_widget', $options );
}
if ( isset( $_POST['rsw-submit'] ) ) {
$options['title'] = strip_tags( stripslashes( $_POST['rsw-title'] ) );
$options['max'] = (int)( $_POST['rsw-max'] );
$options['nofollow'] = isset( $_POST['rsw-nofollow'] );
if ( count( $options['data'] ) > $options['max'] ) {
$options['data'] = array_slice( $options['data'], 0, $options['max'] );
}
update_option( 'recent_searches_widget', $options );
}
$title = attribute_escape( $options['title'] );
$max = attribute_escape( $options['max'] );
$nofollow = $options['nofollow'];
?>
<p><label for="rsw-title"><?php _e('Title:', 'recent-searches-widget'); ?> <input class="widefat" id="rsw-title" name="rsw-title" type="text" value="<?php echo $title; ?>" /></label></p>
<p><label for="rsw-max"><?php _e('Max searches:', 'recent-searches-widget'); ?> <input id="rsw-max" name="rsw-max" type="text" size="3" maxlength="5" value="<?php echo $max; ?>" /></label></p>
<p><label for="rsw-nofollow"><?php _e('Add <code>rel="nofollow"</code> to links:', 'recent-searches-widget'); ?> <input id="rsw-nofollow" name="rsw-nofollow" type="checkbox" value="yes" <?php checked( $nofollow, true ); ?>" /></label></p>
<input type="hidden" id="rsw-submit" name="rsw-submit" value="1" />
<?php
}
// Make string lowercase
function strtolower( $str ) {
if ( function_exists( 'mb_strtolower' ) ) {
return mb_strtolower( $str );
} else {
return strtolower( $str );
}
}
function get_default_options() {
return array(
'title' => '',
'max' => 4,
'nofollow' => true,
);
}
}
// Add functions from WP2.8 for previous WP versions
if ( !function_exists( 'esc_html' ) ) {
function esc_html( $text ) {
return wp_specialchars( $text );
}
}
if ( !function_exists( 'esc_attr' ) ) {
function esc_attr( $text ) {
return attribute_escape( $text );
}
}
// Add functions from WP3.0 for previous WP versions
if ( !function_exists( 'get_search_link' ) ) {
function get_search_link( $query = '' ) {
global $wp_rewrite;
if ( empty($query) )
$search = get_search_query();
else
$search = stripslashes($query);
$permastruct = $wp_rewrite->get_search_permastruct();
if ( empty( $permastruct ) ) {
$link = home_url('?s=' . urlencode($search) );
} else {
$search = urlencode($search);
$search = str_replace('%2F', '/', $search); // %2F(/) is not valid within a URL, send it unencoded.
$link = str_replace( '%search%', $search, $permastruct );
$link = trailingslashit( get_option( 'home' ) ) . user_trailingslashit( $link, 'search' );
}
return apply_filters( 'search_link', $link, $search );
}
}
$wp_recent_searches_widget = new RecentSearchesWidget();
// Show recent searches anywhere in the theme
function rsw_show_recent_searches( $before_list = "<ul>\n<li>", $after_list = "</li>\n</ul>", $between_items = "</li>\n<li>" ) {
global $wp_recent_searches_widget;
$wp_recent_searches_widget->show_recent_searches( $before_list, $after_list, $between_items );
}
} // END
?>
I can't see which part is for clearing up the keywords. Any suggestion? Thanks!
Updated part:
After the clearing history issue solved, this is the next issue i got.
function get_default_options() {
return array(
'title' => '',
'max' => 4, <---it was originally set to 10
'nofollow' => true,
);
}
}
I have set the searched keywords to "4" which was originally set as 10, it should work and display only maximum 4 keywords by right. But, i don't know why the setting seems to follow the very first time i use this plugin. No matter how i tried to set from 0 to 5, the setting never take effect and the keywords there are still displaying as maximum 10 searches. Need help in this!
Any solution?
I found an "archaic" way to do it.
If you search for "store" in the script", at the end of it you'll find the string
update_option( 'recent_searches_widget_data', $data );
If you set $data to 0 (e.g. $data=0;)right before this line and then you try to search something, you'll be able to delete the search history.
Remember to delete the line where you set $data to 0, otherwise the plugin won't start to work again
Edit:
Sorry for the late response, but I have the answers for your question (and also another way to do the previous point).
What I understood is that from the script you can't change after the initialisation the number of elements that have to be shown. When does this happen? When you install the plugin. So you should unzip the folder, change the number of elements in the .php file, zip the folder and install again the plugin.
Not so tricky, but quite long.
Now, the good news.
I don't know if you have ever managed with the database that is behind wp, but there is a table (wp_options) where many part of code that wordpress uses are stored.
Usually here you can also find the data that the plugins set up.
And here we go: in that table there are two rows, called recent_searches_widget and recent_searches_widget_data.
In the first you can find the setting for the number of elements to be shown (its the i:10; that is set by default, if you haven't changed the script yet), in the other you can find the previous searches (and, if you want to delete them, you just need to change the value of the row to 0).